← 返回首页
GitHub - fgm/pflagheaders: Supports HTTP header flags with spf13/pflag · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

fgm/pflagheaders

Go to file
Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
View all files

Repository files navigation

More items

HTTP Headers for spf13/pflag

This package allows use of repeated CLI flags defining HTTP headers, like:

CLI usage

# Long format mycommand --header "Accept: text/plain" --header "Authorization: bearer sometoken" # Short format mycommand -H "Accept: text/plain" -H "Authorization: bearer sometoken" # Repeated headers are supported and combined mycommand -H "X-Array-Header: value1" -H "X-Array-Header: value2" # Will return a slice value with value1 and value2 for key X-Array-Header # Headers are canonicalized mycommand -H "content-type: application/json" # Will have key Content-Type

Code usage

Simple

package main import ( "fmt" "github.com/spf13/pflag" "github.com/fgm/pflagheaders" ) func main() { // HeaderFlag provides a preconfigured default flag h := pflagheaders.HeaderFlag() pflag.Parse() fmt.Printf("Headers:\n%s\n", h) // The resulting http.Header is available after Parse: fmt.Printf("Inner header:\n%#v\n", h.Header) }

In projects using spf13/cobra

// In cmd/root.go package cmd import ( pfh "github.com/fgm/pflagheaders" "github.com/spf13/cobra" // and others ) var header = &pfh.Header{} var rootCmd = &cobra.Command{ /* generated by Cobra */ Run: func(_ *cobra.Command, _ []string) { fmt.Println(header) } } func init() { cobra.OnInitialize(initConfig) // Generated by Cobra // ...other lines generated by Cobra // You can use the provided constants, or use other values. rootCmd.Flags().VarP(header, pfh.NameLong, pfh.NameShort, pfh.Help) }

About

Supports HTTP header flags with spf13/pflag

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Footer

© 2026 GitHub, Inc.