Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mozillazg/go-httpheader
A Go library for encoding structs into Header fields.
https://github.com/mozillazg/go-httpheader
go go-library golang header struct structs
Last synced: about 1 month ago
JSON representation
A Go library for encoding structs into Header fields.
- Host: GitHub
- URL: https://github.com/mozillazg/go-httpheader
- Owner: mozillazg
- License: mit
- Created: 2017-06-24T11:28:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-15T18:34:06.000Z (over 1 year ago)
- Last Synced: 2024-07-31T01:29:37.299Z (3 months ago)
- Topics: go, go-library, golang, header, struct, structs
- Language: Go
- Homepage: https://godoc.org/github.com/mozillazg/go-httpheader
- Size: 55.7 KB
- Stars: 47
- Watchers: 5
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-httpheader - A Go library for encoding structs into Header fields. - ★ 14 (Utilities)
- awesome-go-extra - go-httpheader - 06-24T11:28:06Z|2022-04-09T02:48:07Z| (Utilities / Fail injection)
README
# go-httpheader
go-httpheader is a Go library for encoding structs into Header fields.
[![Build Status](https://github.com/mozillazg/go-httpheader/workflows/CI/badge.svg?branch=master)](https://github.com/mozillazg/go-httpheader/actions)
[![Coverage Status](https://coveralls.io/repos/github/mozillazg/go-httpheader/badge.svg?branch=master)](https://coveralls.io/github/mozillazg/go-httpheader?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/mozillazg/go-httpheader)](https://goreportcard.com/report/github.com/mozillazg/go-httpheader)
[![GoDoc](https://godoc.org/github.com/mozillazg/go-httpheader?status.svg)](https://godoc.org/github.com/mozillazg/go-httpheader)## install
```
go get github.com/mozillazg/go-httpheader
```## usage
```go
package mainimport (
"fmt"
"net/http""github.com/mozillazg/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"},
// }
// decode
var decode Options
httpheader.Decode(h, &decode)
}
```