config.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package rest
  2. import (
  3. "time"
  4. "github.com/wuntsong-org/go-zero-plus/core/service"
  5. )
  6. type (
  7. // MiddlewaresConf is the config of middlewares.
  8. MiddlewaresConf struct {
  9. Trace bool `json:",default=true"`
  10. Log bool `json:",default=true"`
  11. Prometheus bool `json:",default=true"`
  12. MaxConns bool `json:",default=true"`
  13. Breaker bool `json:",default=true"`
  14. Shedding bool `json:",default=true"`
  15. Timeout bool `json:",default=true"`
  16. Recover bool `json:",default=true"`
  17. Metrics bool `json:",default=true"`
  18. MaxBytes bool `json:",default=true"`
  19. Gunzip bool `json:",default=true"`
  20. }
  21. // A PrivateKeyConf is a private key config.
  22. PrivateKeyConf struct {
  23. Fingerprint string
  24. KeyFile string
  25. }
  26. // A SignatureConf is a signature config.
  27. SignatureConf struct {
  28. Strict bool `json:",default=false"`
  29. Expiry time.Duration `json:",default=1h"`
  30. PrivateKeys []PrivateKeyConf
  31. }
  32. // A RestConf is a http service config.
  33. // Why not name it as Conf, because we need to consider usage like:
  34. // type Config struct {
  35. // zrpc.RpcConf
  36. // rest.RestConf
  37. // }
  38. // if with the name Conf, there will be two Conf inside Config.
  39. RestConf struct {
  40. service.ServiceConf
  41. Host string `json:",default=0.0.0.0"`
  42. Port int
  43. CertFile string `json:",optional"`
  44. KeyFile string `json:",optional"`
  45. Verbose bool `json:",optional"`
  46. MaxConns int `json:",default=10000"`
  47. MaxBytes int64 `json:",default=1048576"`
  48. // milliseconds
  49. Timeout int64 `json:",default=3000"`
  50. CpuThreshold int64 `json:",default=900,range=[0:1000]"`
  51. Signature SignatureConf `json:",optional"`
  52. // There are default values for all the items in Middlewares.
  53. Middlewares MiddlewaresConf
  54. // TraceIgnorePaths is paths blacklist for trace middleware.
  55. TraceIgnorePaths []string `json:",optional"`
  56. }
  57. )