options.go 551 B

1234567891011121314151617181920212223
  1. package frame
  2. import "github.com/spf13/pflag"
  3. // Options 配置项
  4. type Options struct {
  5. AddrPort string
  6. ConfigPath string
  7. }
  8. // DefaultOptions 初始化命令行参数
  9. func DefaultOptions() *Options {
  10. return &Options{
  11. AddrPort: ":8080",
  12. ConfigPath: "./config.yaml",
  13. }
  14. }
  15. // AddFlags 增加命令行参数
  16. func (s *Options) AddFlags(fs *pflag.FlagSet) {
  17. fs.StringVar(&s.AddrPort, "addr", s.AddrPort, "The ip address and port for the server on")
  18. fs.StringVarP(&s.ConfigPath, "config", "c", s.ConfigPath, "the config for config path")
  19. }