headerflag

package module
v0.0.0-...-f7c9a98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

README

Summary

go-flag-http-headers provides a simple way to add a command line flag for specifying HTTP headers.

Example

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))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *headerFlag

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL