config.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package rest
  2. import (
  3. "time"
  4. "github.com/zeromicro/go-zero/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. }
  55. )