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: 4 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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