Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The safest Go package for parsing env vars

License

NotificationsYou must be signed in to change notification settings

orsinium-labs/configenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go package for parsing env vars.

The main idea is to enforce (on the package API design level) the best practice of parsing env vars: prevent duplicate names, wrong types, typos, etc. SeeWriting safe-to-use Go libraries on the design principles behind my Go packages, including this one.

Also, try outcliff, a package for safely parsing CLI args.

Installation

go get github.com/orsinium-labs/configenv

Usage

Given the following parser:

typeConfigstruct {DebugboolEnvstring}config:=Config{}vars:= configenv.Vars{"DEBUG":configenv.Required(configenv.Bool(&config.Debug)),"ENV":configenv.String(&config.Env),}err:=vars.Parse(configenv.Config{Prefix:"BE_"})

And the following env vars:

export BE_DEBUG=trueexport BE_ENV=prod

You will getConfig{Debug: true, Env: "prod"}

If you instead ofBE_DEBUG=true provideDEBUG=true,BE_DEUG=true, orBE_DEBUG=maybe, the parser will detect it and return an error.

About

The safest Go package for parsing env vars

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp