server_run.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package options
  2. import (
  3. "github.com/spf13/pflag"
  4. )
  5. // ServerRunOptions 服务运行配置
  6. type ServerRunOptions struct {
  7. Mode string `json:"mode" mapstructure:"mode"`
  8. Healthz bool `json:"healthz" mapstructure:"healthz"`
  9. Middlewares []string `json:"middlewares" mapstructure:"middlewares"`
  10. }
  11. func NewServerRunOptions() *ServerRunOptions {
  12. return &ServerRunOptions{
  13. Mode: "release",
  14. Healthz: false,
  15. Middlewares: []string{},
  16. }
  17. }
  18. func (s *ServerRunOptions) Validate() []error {
  19. var errors []error
  20. return errors
  21. }
  22. func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
  23. // Note: the weird ""+ in below lines seems to be the only way to get gofmt to
  24. // arrange these text blocks sensibly. Grrr.
  25. fs.StringVar(&s.Mode, "server.mode", s.Mode, ""+
  26. "Start the server in a specified server mode. Supported server mode: debug, test, release.")
  27. fs.BoolVar(&s.Healthz, "server.healthz", s.Healthz, ""+
  28. "Add self readiness check and install /healthz router.")
  29. fs.StringSliceVar(&s.Middlewares, "server.middlewares", s.Middlewares, ""+
  30. "List of allowed middlewares for server, comma separated. If this list is empty default middlewares will be used.")
  31. }