You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
alantong
179aace121
|
6 years ago | |
---|---|---|
.. | ||
.bumpversion.cfg | 6 years ago | |
.gitignore | 6 years ago | |
.travis.yml | 6 years ago | |
CHANGELOG.md | 6 years ago | |
LICENSE | 6 years ago | |
Makefile | 6 years ago | |
README.md | 6 years ago | |
encode.go | 6 years ago | |
encode_test.go | 6 years ago | |
example_test.go | 6 years ago |
README.md
go-httpheader
go-httpheader is a Go library for encoding structs into Header fields.
install
go get -u github.com/tencentyun/go-httpheader
usage
package main
import (
"fmt"
"net/http"
"github.com/tencentyun/go-httpheader"
)
type Options struct {
hide string
ContentType string `header:"Content-Type"`
Length int
XArray []string `header:"X-Array"`
TestHide string `header:"-"`
IgnoreEmpty string `header:"X-Empty,omitempty"`
IgnoreEmptyN string `header:"X-Empty-N,omitempty"`
CustomHeader http.Header
}
func main() {
opt := Options{
hide: "hide",
ContentType: "application/json",
Length: 2,
XArray: []string{"test1", "test2"},
TestHide: "hide",
IgnoreEmptyN: "n",
CustomHeader: http.Header{
"X-Test-1": []string{"233"},
"X-Test-2": []string{"666"},
},
}
h, _ := httpheader.Header(opt)
fmt.Printf("%#v", h)
// h:
// http.Header{
// "X-Test-1": []string{"233"},
// "X-Test-2": []string{"666"},
// "Content-Type": []string{"application/json"},
// "Length": []string{"2"},
// "X-Array": []string{"test1", "test2"},
// "X-Empty-N": []string{"n"},
//}
}