All Projects → mozillazg → go-httpheader

mozillazg / go-httpheader

Licence: MIT license
A Go library for encoding structs into Header fields.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to go-httpheader

straf
Convert Golang Struct To GraphQL Object On The Fly
Stars: ✭ 33 (-13.16%)
Mutual labels:  structs, struct
react-sticky-header
🍯 A sticky header for React.js
Stars: ✭ 55 (+44.74%)
Mutual labels:  header
veryfi-go
Go module for communicating with the Veryfi OCR API
Stars: ✭ 18 (-52.63%)
Mutual labels:  go-library
http
Basic HTTP primitives which can be shared by servers and clients.
Stars: ✭ 75 (+97.37%)
Mutual labels:  header
python-cstruct
C-style structs for Python
Stars: ✭ 38 (+0%)
Mutual labels:  struct
govalidators
struct 验证器,内置大部分常用验证,可自定义
Stars: ✭ 56 (+47.37%)
Mutual labels:  struct
vscodefileheader
VSCode File Header
Stars: ✭ 17 (-55.26%)
Mutual labels:  header
LandscapeView
Animated landscape generator
Stars: ✭ 89 (+134.21%)
Mutual labels:  header
random
Random data generator AKA faker
Stars: ✭ 14 (-63.16%)
Mutual labels:  go-library
get header
This function is similar to the get_headers function
Stars: ✭ 35 (-7.89%)
Mutual labels:  header
cstruct-go
a fast c-style struct packer & unpacker for golang
Stars: ✭ 28 (-26.32%)
Mutual labels:  struct
poop
Firefox extension that prevents sending Origin headers when they are least likely to be necessary, to protect your privacy.
Stars: ✭ 36 (-5.26%)
Mutual labels:  header
c2ats
generate ATS interface from C code
Stars: ✭ 19 (-50%)
Mutual labels:  header
table
Produces a string that represents slice data in a text table, inspired by gajus/table.
Stars: ✭ 130 (+242.11%)
Mutual labels:  struct
react-sticky-headroom
A React Component to hide a Header using CSS sticky position
Stars: ✭ 22 (-42.11%)
Mutual labels:  header
go-localize
i18n (Internationalization and localization) engine written in Go, used for translating locale strings.
Stars: ✭ 45 (+18.42%)
Mutual labels:  go-library
go-opendota
Go client library for accessing the OpenDota API
Stars: ✭ 34 (-10.53%)
Mutual labels:  go-library
react-native-header-search-bar
Fully customizable header search bar for React Native
Stars: ✭ 101 (+165.79%)
Mutual labels:  header
telegram
📚 Golang bindings for Telegram API
Stars: ✭ 15 (-60.53%)
Mutual labels:  go-library
http
Handy HTTP utility such as method constants and status codes
Stars: ✭ 20 (-47.37%)
Mutual labels:  header

go-httpheader

go-httpheader is a Go library for encoding structs into Header fields.

Build Status Coverage Status Go Report Card GoDoc

install

go get -u github.com/mozillazg/go-httpheader

usage

package main

import (
	"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)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].