zdpgo_env

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 3 Imported by: 1

README

zdpgo_env

Golang读取环境变量的库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Debug bool `json:"debug" yaml:"debug" env:"debug"`
}

type Env

type Env struct {
	// 加载配置文件中的变量到环境变量
	Load func(filenames ...string) (err error)

	// 读取环境变量到配置对象
	Read func(config interface{}, opts ...envconfig.Options) error
}

Env 操作环境变量的核心对象

func New

func New() *Env

func (*Env) Get

func (e *Env) Get(key string) string

Get 根据键获取环境变量中的值

func (*Env) GetDefault

func (e *Env) GetDefault(key, defaultValue string) string

GetDefault 获取环境变量信息,找不到则使用默认值

type Load

type Load interface {
	// Load 加载文件中定义的环境变量到系统环境变量中
	Load(filenames ...string) (err error)
}

Load 加载文件接口

type Reader

type Reader interface {
	// Read 读取环境变量进配置中
	Read(config interface{}, opts ...envconfig.Options) error
}

Directories

Path Synopsis
examples
z01_hello command
libs

Jump to

Keyboard shortcuts

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