Documentation
ยถ
Index ยถ
- Variables
- func HookFuncDefault() mapstructure.DecodeHookFuncType
- func HookFuncEnvRender() mapstructure.DecodeHookFuncType
- func HookFuncStringToBool() mapstructure.DecodeHookFuncType
- func HookFuncStringToSlogLevel() mapstructure.DecodeHookFuncType
- func Load[T any](obj *T, uri string) error
- func LoadCtx[T any](ctx context.Context, obj *T, uri string) error
- func LoadFlags[T any](result *T) error
- func LoadFlagsCtx[T any](ctx context.Context, config *T) error
- func LoadWithFlags[T any](obj *T, uriOrFlag string) error
- func LoadWithFlagsCtx[T any](ctx context.Context, obj *T, uriOrFlag string) error
- type ConfEvent
- type ConfOpt
- func (c *ConfOpt[T]) Close() error
- func (c *ConfOpt[T]) Load(obj *T) error
- func (c *ConfOpt[T]) LoadCtx(ctx context.Context, obj *T) error
- func (c *ConfOpt[T]) Parse() (*T, error)
- func (c *ConfOpt[T]) ParseCtx(ctx context.Context) (*T, error)
- func (c *ConfOpt[T]) Subscribe() (<-chan *ConfEvent[T], error)
- func (c *ConfOpt[T]) SubscribeCtx(ctx context.Context) (<-chan *ConfEvent[T], error)
Constants ยถ
This section is empty.
Variables ยถ
var DefaultParserConfig = mapstructure.DecoderConfig{ DecodeHook: mapstructure.ComposeDecodeHookFunc( HookFuncDefault(), HookFuncEnvRender(), HookFuncStringToBool(), HookFuncStringToSlogLevel(), mapstructure.StringToTimeDurationHookFunc(), mapstructure.StringToSliceHookFunc(","), mapstructure.StringToBasicTypeHookFunc(), ), TagName: "json", WeaklyTypedInput: true, ErrorUnused: false, ZeroFields: false, MatchName: func(mapKey, fieldName string) bool { return strings.EqualFold(strings.ReplaceAll(mapKey, "_", ""), fieldName) }, }
DefaultParserConfig ้ป่ฎค่งฃๆๅจ้ ็ฝฎ
Functions ยถ
func HookFuncDefault ยถ
func HookFuncDefault() mapstructure.DecodeHookFuncType
HookFuncDefault ้ป่ฎคๅผ้ฉๅญ๏ผๅฝๅ ถไป้ฉๅญ้ฝๆ ๆณๅค็ๆถๆไพ้ป่ฎคๅผ
func HookFuncEnvRender ยถ
func HookFuncEnvRender() mapstructure.DecodeHookFuncType
HookFuncEnvRender ็ฏๅขๅ้ๆธฒๆ้ฉๅญ
func HookFuncStringToBool ยถ
func HookFuncStringToBool() mapstructure.DecodeHookFuncType
HookFuncStringToBool ๅญ็ฌฆไธฒๅๆฐๅญๅฐๅธๅฐๅผ็้ฉๅญ
func HookFuncStringToSlogLevel ยถ
func HookFuncStringToSlogLevel() mapstructure.DecodeHookFuncType
HookFuncStringToSlogLevel ๅญ็ฌฆไธฒๅๆฐๅญๅฐslog.Level็้ฉๅญ
func LoadCtx ยถ
LoadCtx loads configuration from URI with context and unmarshals it to the provided object
func LoadFlags ยถ
LoadFlags parses struct fields and adds command-line flags for fields with 'usage' tag, parses command-line flags, maps flag values to the struct, and modifies the provided struct pointer This is a public entry function for flag parsing functionality
func LoadFlagsCtx ยถ
LoadFlagsCtx parses struct fields and adds command-line flags for fields with 'usage' tag with context support, parses command-line flags, maps flag values to the struct, and modifies the provided struct pointer The context can be used for cancellation or timeout during flag parsing
func LoadWithFlags ยถ
LoadWithFlags loads configuration from URI or flag and unmarshals it to the provided object If uriOrFlag is a valid URI, it will be used as the configuration source If uriOrFlag is not a URI, it will be treated as a flag name for configuration It also parses the struct type T and adds flags for fields with 'usage' tag
func LoadWithFlagsCtx ยถ
LoadWithFlagsCtx loads configuration from URI or flag with context and unmarshals it to the provided object If uriOrFlag is a valid URI, it will be used as the configuration source If uriOrFlag is not a URI, it will be treated as a flag name for configuration It also parses the struct type T and adds flags for fields with 'usage' tag The context can be used for cancellation or timeout during loading
Types ยถ
type ConfEvent ยถ
type ConfOpt ยถ
type ConfOpt[T any] struct { ParserConf mapstructure.DecoderConfig // contains filtered or unexported fields }
func NewWithFlags ยถ
NewWithFlags creates a configuration loader that reads URI from command-line flags If uriOrFlag is a valid URI, it will be used as the configuration source If uriOrFlag is not a URI, it will be treated as a flag name for configuration It also parses the struct type T and adds flags for fields with 'usage' tag
func NewWithFlagsCtx ยถ
NewWithFlagsCtx creates a configuration loader that reads URI from command-line flags with context support If uriOrFlag is a valid URI, it will be used as the configuration source If uriOrFlag is not a URI, it will be treated as a flag name for configuration It also parses the struct type T and adds flags for fields with 'usage' tag The context can be used for cancellation or timeout during flag parsing