https://github.com/graphaelli/go-flag-http-headers
https://github.com/graphaelli/go-flag-http-headers
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/graphaelli/go-flag-http-headers
- Owner: graphaelli
- License: apache-2.0
- Created: 2022-09-23T02:50:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-23T02:52:24.000Z (over 3 years ago)
- Last Synced: 2025-04-03T11:29:02.847Z (about 1 year ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Summary
`go-flag-http-headers` provides a simple way to add a command line flag for specifying HTTP headers.
## Example
```go
package main
import (
"flag"
"fmt"
"net/http"
"net/http/httputil"
headerflag "github.com/graphaelli/go-flag-http-headers"
)
func main() {
hf := headerflag.New()
flag.Var(hf, "header", "HTTP header, can be specified multiple times")
flag.Parse()
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
for h, vs := range hf.Headers() {
for _, v := range vs {
req.Header.Add(h, v)
}
}
b, _ := httputil.DumpRequest(req, false)
fmt.Println(string(b))
}
```