goenv

command module
v0.0.0-...-11bf18d Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README

Go ENV

This utility is designed to allow you to let you interact with .env files in a manner consistent with .env.local, .env.develop, .env.production, etc., and we have shorter hand notations for interacting with .env files.

Installation

go get github.com/andreimerlescu/goenv@latest
Package env

The basis behind env is the env package, which can be used in other Go applications and is licensed as Apache 2.0.

go get -u github.com/andreimerlescu/goenv/env

The README.md has more information about using the package.

Usage

I wrote this package because sometimes I just need to work with an env file, even if it doesn't yet exist. This is particularly useful for input validation of env files and the ability to transform the syntax of the .env file into multiple formats. The test.sh file has the summary of arguments that are best to run for the package.

go install github.com:andreimerlescu/goenv@latest
goenv -init -write -file n8n.env
goenv -write -file n8n.env -add -env DATA_FOLDER -value "$(pwd)"
goenv -write -file n8n.env -add -env DOMAIN -value "gh.dev"
goenv -write -file n8n.env -add -env SUBDOMAIN -value "n8n"
goenv -write -file n8n.env -add -env SSL_EMAIL -value "[email protected]"
goenv -file n8n.env -print
goenv -file n8n.env -xml
goenv -file n8n.env -toml
goenv -file n8n.env -has -env GENERIC_TIMEZONE

Testing

andrei@GitHub:~/repos/goenv|master⚡ ⇒  make all
Summary generated: summaries/summary.2025.08.09.19.28.57.UTC.md
Building goenv binary...
Clean successful: goenv
Build successful: goenv

[email protected]:. ⚡ Test #1 ⇒  goenv -file sample.env -has -env HOSTNAME
[email protected]:. ⚡ Test #2 ⇒  goenv -file sample.env -has -env NON_EXISTENT
[email protected]:. ⚡ Test #3 ⇒  goenv -file sample.env -is -env DATABASE -value test_data
[email protected]:. ⚡ Test #4 ⇒  goenv -file sample.env -is -env DATABASE -value wrong_data
[email protected]:. ⚡ Test #5 ⇒  goenv -file sample.env -print
AWS_REGION=us-west-2
OUTPUT=json
HOSTNAME=localhost
DBUSER=readonly
DBPASS=readonly
DATABASE=test_data
[email protected]:. ⚡ Test #6 ⇒  goenv -file sample.env -json
{
  "AWS_REGION": "us-west-2",
  "DATABASE": "test_data",
  "DBPASS": "readonly",
  "DBUSER": "readonly",
  "HOSTNAME": "localhost",
  "OUTPUT": "json"
}
[email protected]:. ⚡ Test #7 ⇒  goenv -file sample.env -yaml
---
AWS_REGION: "us-west-2" 
OUTPUT: "json" 
HOSTNAME: "localhost" 
DBUSER: "readonly" 
DBPASS: "readonly" 
DATABASE: "test_data" 
[email protected]:. ⚡ Test #8 ⇒  goenv -file sample.env -toml
DBPASS: "readonly" 
DATABASE: "test_data" 
AWS_REGION: "us-west-2" 
OUTPUT: "json" 
HOSTNAME: "localhost" 
DBUSER: "readonly" 
[email protected]:. ⚡ Test #9 ⇒  goenv -file sample.env -ini
[default]
OUTPUT = json
HOSTNAME = localhost
DBUSER = readonly
DBPASS = readonly
DATABASE = test_data
AWS_REGION = us-west-2
[email protected]:. ⚡ Test #10 ⇒  goenv -file sample.env -xml
<?xml version="1.0" encoding="UTF-8"?>
<env>
   <AWS_REGION>us-west-2</AWS_REGION>
   <OUTPUT>json</OUTPUT>
   <HOSTNAME>localhost</HOSTNAME>
   <DBUSER>readonly</DBUSER>
   <DBPASS>readonly</DBPASS>
   <DATABASE>test_data</DATABASE>
</env>
[email protected]:. ⚡ Test #11 ⇒  goenv -file sample.env -write -add -env NEW_KEY -value 'a new value'
[email protected]:. ⚡ Test #12 ⇒  goenv -file sample.env -has -env NEW_KEY
[email protected]:. ⚡ Test #13 ⇒  goenv -file sample.env -write -add -env HOSTNAME -value 'another-host'
[email protected]:. ⚡ Test #14 ⇒  goenv -file sample.env -is -env HOSTNAME -value localhost
[email protected]:. ⚡ Test #15 ⇒  goenv -file sample.env -write -rm -env OUTPUT
[email protected]:. ⚡ Test #16 ⇒  goenv -file sample.env -not -has -env OUTPUT
[email protected]:. ⚡ Test #17 ⇒  goenv -file new.env -add -env HELLO -value world -write
[email protected]:. ⚡ Test #18 ⇒  goenv -file new.env -is -env HELLO -value world
[email protected]:. ⚡ Test #19 ⇒  goenv -file sample.env -v
v0.0.2
[email protected]:. ⚡ Test #20 ⇒  goenv -file non_existent_file.env -add -env FOO -value bar || echo "Test success because we expected an error here."                                                                                                      
[email protected]:. ⚡ Test #21 ⇒  goenv -file non_existent_file.env -add -env FOO -value bar -write
All 21 tests PASS!
NEW: bin/goenv-darwin-amd64
NEW: bin/goenv-darwin-arm64
NEW: bin/goenv-linux-amd64
NEW: bin/goenv-darwin-arm64
NEW: bin/goenv.exe
NEW: /Users/andrei/go/bin/goenv

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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