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.

59 lines
1.2 KiB

6 years ago
  1. # go-httpheader
  2. go-httpheader is a Go library for encoding structs into Header fields.
  3. ## install
  4. `go get -u github.com/tencentyun/go-httpheader`
  5. ## usage
  6. ```go
  7. package main
  8. import (
  9. "fmt"
  10. "net/http"
  11. "github.com/tencentyun/go-httpheader"
  12. )
  13. type Options struct {
  14. hide string
  15. ContentType string `header:"Content-Type"`
  16. Length int
  17. XArray []string `header:"X-Array"`
  18. TestHide string `header:"-"`
  19. IgnoreEmpty string `header:"X-Empty,omitempty"`
  20. IgnoreEmptyN string `header:"X-Empty-N,omitempty"`
  21. CustomHeader http.Header
  22. }
  23. func main() {
  24. opt := Options{
  25. hide: "hide",
  26. ContentType: "application/json",
  27. Length: 2,
  28. XArray: []string{"test1", "test2"},
  29. TestHide: "hide",
  30. IgnoreEmptyN: "n",
  31. CustomHeader: http.Header{
  32. "X-Test-1": []string{"233"},
  33. "X-Test-2": []string{"666"},
  34. },
  35. }
  36. h, _ := httpheader.Header(opt)
  37. fmt.Printf("%#v", h)
  38. // h:
  39. // http.Header{
  40. // "X-Test-1": []string{"233"},
  41. // "X-Test-2": []string{"666"},
  42. // "Content-Type": []string{"application/json"},
  43. // "Length": []string{"2"},
  44. // "X-Array": []string{"test1", "test2"},
  45. // "X-Empty-N": []string{"n"},
  46. //}
  47. }
  48. ```