package options import ( "github.com/spf13/pflag" ) // ServerRunOptions 服务运行配置 type ServerRunOptions struct { Mode string `json:"mode" mapstructure:"mode"` Healthz bool `json:"healthz" mapstructure:"healthz"` Middlewares []string `json:"middlewares" mapstructure:"middlewares"` } func NewServerRunOptions() *ServerRunOptions { return &ServerRunOptions{ Mode: "release", Healthz: false, Middlewares: []string{}, } } func (s *ServerRunOptions) Validate() []error { var errors []error return errors } func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) { // Note: the weird ""+ in below lines seems to be the only way to get gofmt to // arrange these text blocks sensibly. Grrr. fs.StringVar(&s.Mode, "server.mode", s.Mode, ""+ "Start the server in a specified server mode. Supported server mode: debug, test, release.") fs.BoolVar(&s.Healthz, "server.healthz", s.Healthz, ""+ "Add self readiness check and install /healthz router.") fs.StringSliceVar(&s.Middlewares, "server.middlewares", s.Middlewares, ""+ "List of allowed middlewares for server, comma separated. If this list is empty default middlewares will be used.") }