envconf

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Overview

Package envconf 从环境变量加载配置项用于初始化具体的配置对象。 用法:

type Config struct {
		Addr  string `env:"ADDR" default:""`
		Level string `env:"LEVEL" required:"true"`
}

config := &Config{}

if err := Load(config); err != nil {
		return err
}

配置项支持的类型有:

	bool
	int
	int64
 uint64
	float64
	string
	time.Duration
	其他非基本类型使用json解析

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(obj interface{}, envOpts ...map[string]string) error

Load 分析配置对象 obj,并从环境变量里获取值初始化配置对象.

func MustLoad

func MustLoad(obj interface{})

MustLoad 必须 Load 配置成功,失败直接 panic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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