Documentation
¶
Index ¶
- Constants
- Variables
- func AssignValue(value string, field reflect.Value) error
- func GetExistEnv(name ...string) (string, bool)
- func HookTimeDuration(in reflect.Type, out reflect.Type, data any) (any, error)
- func OrderLoaders(loaders map[string]LoadHolder) []string
- func TagValue(field reflect.StructField, tags ...string) string
- func TagValueM(field reflect.StructField, tags ...string) *string
- type HookFunc
- type LoadHolder
- type Loader
- type Option
- type OptionFunc
- type Order
Constants ¶
View Source
const ( NameDefault = "default" NameConsul = "consul" NameVault = "vault" NameHTTP = "http" NameFile = "file" NameEnv = "env" )
Variables ¶
View Source
var ( ErrSkipLoader = errors.New("skip loader") ErrMissingOpt = errors.New("missing option") )
View Source
var ( OrderDefault = &Order{ Before: []string{NameConsul, NameVault, NameHTTP, NameFile, NameEnv}, } OrderConsul = &Order{ Before: []string{NameVault, NameHTTP, NameFile, NameEnv}, After: []string{NameDefault}, } OrderVault = &Order{ Before: []string{NameHTTP, NameFile, NameEnv}, After: []string{NameDefault, NameConsul}, } OrderHTTP = &Order{ Before: []string{NameFile, NameEnv}, After: []string{NameDefault, NameConsul, NameVault}, } OrderFile = &Order{ Before: []string{NameEnv}, After: []string{NameDefault, NameConsul, NameVault, NameHTTP}, } OrderEnv = &Order{ After: []string{NameDefault, NameConsul, NameVault, NameHTTP, NameFile}, } )
View Source
var Loaders = map[string]LoadHolder{}
Functions ¶
func AssignValue ¶
AssignValue assigns the value to the field.
func GetExistEnv ¶
func HookTimeDuration ¶
HookTimeDuration for time.Duration
func OrderLoaders ¶ added in v0.2.0
func OrderLoaders(loaders map[string]LoadHolder) []string
Types ¶
type HookFunc ¶
type HookFunc = struct2.HookDecodeFunc
HookFunc get input, output and data and return modified data.
type LoadHolder ¶ added in v0.2.0
type Option ¶
type Option struct {
Tag string
Name string
Hooks []HookFunc
MapDecoder func(input any, output any) error
Logger logadapter.Adapter
}
func NewOption ¶
func NewOption(opts ...OptionFunc) *Option
type OptionFunc ¶ added in v0.2.0
type OptionFunc func(*Option)
func WithHooks ¶
func WithHooks(hooks ...HookFunc) OptionFunc
WithHooks sets the hooks for conversion.
func WithLogger ¶
func WithLogger(logger logadapter.Adapter) OptionFunc
WithLogger sets the logger for logging.
func WithMapDecoder ¶
func WithMapDecoder(decoder func(input any, output any) error) OptionFunc
WithMapDecoder sets the decoder for conversion between map and struct.
- output is the target struct
func WithName ¶
func WithName(name string) OptionFunc
WithName sets the name for loader.
Loader will look this name for file, config name, etc.
func WithTag ¶
func WithTag(tag string) OptionFunc
WithTag sets the tag name for struct field.
- loaders may use this tag to load the configuration.
Click to show internal directories.
Click to hide internal directories.