configor

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 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 unmarshals configurations to struct from provided data using the default Configor.

func LoadFile

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

LoadFile unmarshals configurations to struct from provided files using the default Configor.

func Register

func Register(suffix string, f Unmarshal)

Register registers a new unmarshal function for a file extension.

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) error

Load unmarshals configurations to struct from provided data.

func (*Configor) LoadFile

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

LoadFile unmarshals configurations to struct from provided files.

type Unmarshal

type Unmarshal func([]byte, any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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