Documentation ¶
Index ¶
- Variables
- func LoadConfig(dst interface{}, opts ...ConfigOption) error
- func LoadEnv(prefix string, v interface{}) error
- func LoadFlag(flagSet *flag.FlagSet, args []string, conf interface{}) error
- func LoadPFlag(flagSet *pflag.FlagSet, args []string, conf interface{}) error
- func LoadYaml(filepath string, conf interface{}) error
- func Marshal(v interface{}) ([]byte, error)
- func Unmarshal(data []byte, v interface{}) error
- type ConfigOption
- type ConfigOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // MarshalOptions is a configurable JSON format marshaller. MarshalOptions = protojson.MarshalOptions{ UseProtoNames: true, EmitUnpopulated: true, EmitDefaultValues: true, } // UnmarshalOptions is a configurable JSON format parser. UnmarshalOptions = protojson.UnmarshalOptions{ DiscardUnknown: true, } )
Functions ¶
func LoadConfig ¶
func LoadConfig(dst interface{}, opts ...ConfigOption) error
LoadConfig 加载配置, 优先级为 flag > env > yaml
Types ¶
type ConfigOption ¶
type ConfigOption func(*ConfigOptions)
func WithFlag ¶
func WithFlag(flagSet *flag.FlagSet, args []string) ConfigOption
WithFlag 从 flag 加载配置
func WithPFlag ¶
func WithPFlag(pflagSet *pflag.FlagSet, args []string) ConfigOption
WithPFlag 从 pflag 加载配置
func WithYaml ¶
func WithYaml(filepath string) ConfigOption
WithYaml 从 YAML 加载配置, 依赖 json flag , 需要定义正确的数据类型
type ConfigOptions ¶
type ConfigOptions struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.