一个由@matansh开发的Go(lang)配置库

59 阅读1分钟

一个由@matansh开发的Go(lang)配置库

使用方法

import "github.com/matansh/enver/config"

type Config struct {
	LogLevel          string `env:"LOG_LEVEL"`
	Port              int64  `env:"PORT"`
	FeatureFlag       bool   `env:"TURN_ON_FEATURE"`
	ExplicitlyIgnored string `env:"-"` // passing "-" instructs the lib not to populate this field
	ImplicitlyIgnored string           // untagged struct fields will be ignored
}

func main() {
	var cfg Config
	
	errs := config.LoadEnv(&cfg)
	if len(errs) != 0 {
		// failed to load config
	}
}

背景介绍

这个库的目的是帮助项目实施十二个因素的应用方法--12factor.net/

脚注

这个库故意不依赖,以减少其导入者的依赖树,欢迎你😉