config

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNonPointer = newE("mapStruct of non-pointer")
	ErrorNilInput   = newE("mapStruct of nil")
	ErrorNonStruct  = newE("mapStruct of non-struct ptr")
)

预定义的一些异常

Functions

func MapConfig

func MapConfig(dest interface{}) error

MapConfig 可以从环境变量读取配置灌入到 dest 中,dest 必须是一个指向结构体的指针, 会解析结构体每个字段,通过结构体标签得到这个字段对应的环境变量名,自动将从环境变量读取 到的字符串值转为 dest 字段对应的类型并为其赋值 如果 dest 为 nil,返回 ErrorNilInput 如果 dest 不是一个指针,返回 ErrorNonPointer 如果 dest 指针指向的值不是一个结构体,返回 ErrorNonStruct 如果环境变量的值转为字段相应类型时发生错误,立即返回相应的错误

MapConfig 允许字段值为空

func MustMapConfig

func MustMapConfig(dest interface{}) error

MustMapConfig 所有可导出字段都不允许为空

Types

type ConfigError

type ConfigError struct {
	// contains filtered or unexported fields
}

ConfigError mapper 过程中会出现的错误

func (ConfigError) Error

func (c ConfigError) Error() string

Error error interface

Jump to

Keyboard shortcuts

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