Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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
NotificationsYou must be signed in to change notification settings

taybart/env

Repository files navigation

test

Easy environments in go!

package mainimport ("fmt""os""github.com/taybart/env")funcmain() {// set some envos.Setenv("ENVS_ARE_FUN","true")os.Setenv("WOOT",`{ "yes": "even_json" }`)// Declare our env for this fileenv.Add([]string{"ENVS_ARE_FUN","WOOT","PORT=8080",// default values"INSECURE?",// optional values, default to go "zero values"  })config:=struct{Yesstring`json:"yes"`  }{}env.JSON("WOOT",&config)fmt.Println(config.Yes)// check if vars are definedif!env.Has("INSECURE") {fmt.Println("INSECURE is not defined")  }// default zero valuesif!env.Bool("INSECURE") {fmt.Println("This is super secure now")  }ifenv.Bool("ENVS_ARE_FUN") {fmt.Println("They really are...")  }// look up random envshome:=env.Get("HOME")fmt.Printf("HOME=%s\n",home)}

Generate env requirements with the CLI

Installation

go install github.com/taybart/env/cmd/scanenv@latest

Generate env file

Single File:

$ scanenv -f ./main.goENVS_ARE_FUN=""ENVS_ARE_COMPLICATED=""PORT="8080"INSECURE="Value marked as optional"

Recursive Directory:

$ scanenv -d.ENVS_ARE_FUN=""ENVS_ARE_COMPLICATED=""PORT="8080"INSECURE="Value marked as optional"

Get where env is declared

$ scanenv -d. -p# ./main.goENVS_ARE_FUN=""ENVS_ARE_COMPLICATED=""PORT="8080"INSECURE="Value marked as optional"# ./util/redis.goREDIS_PORT=""

Validate .env file

$ scanenv -d ./ -validate .env[ERROR] Missing required envENV[WARN] Using default valuefor PORT=69

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp