package config import ( "encoding/json" "gogs.tyduyong.com/duyong/dy-pkg/app/flagsets" "gogs.tyduyong.com/duyong/dy-pkg/app/options" ) type Config struct { ServerRunOptions *options.ServerRunOptions `json:"server" mapstructure:"server"` InsecureServeOptions *options.InsecureServeOptions `json:"insecure" mapstructure:"insecure"` SecureServingOptions *options.SecureServingOptions `json:"secure" mapstructure:"secure"` PGSQLOptions *options.PGSQLOptions `json:"pgsql" mapstructure:"pgsql"` LogOptions *options.LogOptions `json:"log" mapstructure:"log"` JwtOptions *options.JwtOptions `json:"jwt" mapstructure:"jwt"` FeatureOptions *options.FeatureOptions `json:"feature" mapstructure:"feature"` GRPCOptions *options.GRPCOptions `json:"grpc" mapstructure:"grpc"` } func NewConfig() *Config { o := Config{ ServerRunOptions: options.NewServerRunOptions(), InsecureServeOptions: options.NewInsecureServingOptions(), SecureServingOptions: options.NewSecureServingOptions(), PGSQLOptions: options.NewPGSQLOptions(), JwtOptions: options.NewJwtOptions(), FeatureOptions: options.NewFeatureOptions(), LogOptions: options.NewLogOptions(), GRPCOptions: options.NewGRPCOptions(), } return &o } func (o *Config) Flags() (fss flagsets.NamedFlagSets) { o.ServerRunOptions.AddFlags(fss.FlagSet("server run")) o.InsecureServeOptions.AddFlags(fss.FlagSet("insecure server")) o.PGSQLOptions.AddFlags(fss.FlagSet("mysql")) o.JwtOptions.AddFlags(fss.FlagSet("jwt")) o.FeatureOptions.AddFlags(fss.FlagSet("features")) o.LogOptions.AddFlags(fss.FlagSet("logs")) return fss } func (o *Config) Validate() []error { var errs []error errs = append(errs, o.ServerRunOptions.Validate()...) errs = append(errs, o.InsecureServeOptions.Validate()...) errs = append(errs, o.PGSQLOptions.Validate()...) errs = append(errs, o.JwtOptions.Validate()...) errs = append(errs, o.FeatureOptions.Validate()...) errs = append(errs, o.LogOptions.Validate()...) return errs } func (o *Config) String() string { data, _ := json.Marshal(o) return string(data) } // Complete set default Options. func (o *Config) Complete() error { return nil }