loader

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSkipLoader = errors.New("skip loader")
	ErrMissingOpt = errors.New("missing option")
)

Functions

func AssignValue

func AssignValue(value string, field reflect.Value) error

AssignValue assigns the value to the field.

func GetExistEnv

func GetExistEnv(name ...string) (string, bool)

func HookTimeDuration

func HookTimeDuration(in reflect.Type, out reflect.Type, data interface{}) (interface{}, error)

HookTimeDuration for time.Duration

func NewOption

func NewOption(opts ...Option) *option

func TagValue

func TagValue(field reflect.StructField, tags ...string) string

TagValue returns the value of the tag in the field in order of the tags.

If the tag is not found, it will return the field name.

func TagValueM

func TagValueM(field reflect.StructField, tags ...string) string

TagValueM returns the value of the tag in the field in order of the tags.

If the tag is not found, it will return an empty string.

Types

type HookFunc

type HookFunc func(reflect.Type, reflect.Type, interface{}) (interface{}, error)

HookFunc get input, output and data and return modified data.

type Option

type Option func(*option)

func WithHooks

func WithHooks(hooks ...HookFunc) Option

WithHooks sets the hooks for conversion.

func WithLogger

func WithLogger(logger logadapter.Adapter) Option

WithLogger sets the logger for logging.

func WithMapDecoder

func WithMapDecoder(decoder func(input interface{}, output interface{}) error) Option

WithMapDecoder sets the decoder for conversion between map and struct.

  • output is the target struct

func WithName

func WithName(name string) Option

WithName sets the name for loader.

Loader will look this name for file, config name, etc.

func WithTag

func WithTag(tag string) Option

WithTag sets the tag name for struct field.

  • loaders may use this tag to load the configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL