configor

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = &Configor{
	LoadEnv:   false,
	EnvPrefix: "",
	Unmarshal: toml.Unmarshal,
	Validator: validator.New().Struct,
}

Functions

func Load

func Load(dst any, data ...[]byte) error

Load will unmarshal configurations to struct from files that you provide

func LoadFile

func LoadFile(dst any, files ...string) error

Load will unmarshal configurations to struct from files that you provide

func Register

func Register(suffix string, f Unmarshal)

Types

type Configor

type Configor struct {
	LoadEnv   bool            // 是否读取环境变量
	EnvPrefix string          // 环境变量前缀
	Unmarshal Unmarshal       // 解析器
	Validator func(any) error // 校验器
}

func (*Configor) Load

func (c *Configor) Load(dst any, data ...[]byte) (err error)

func (*Configor) LoadFile

func (c *Configor) LoadFile(dst any, files ...string) error

Load will unmarshal configurations to struct from files that you provide

type Unmarshal

type Unmarshal func([]byte, any) error

Jump to

Keyboard shortcuts

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