Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cuonglm/envim
Go environment variables for human
https://github.com/cuonglm/envim
environment go golang golang-tools
Last synced: 26 days ago
JSON representation
Go environment variables for human
- Host: GitHub
- URL: https://github.com/cuonglm/envim
- Owner: cuonglm
- License: other
- Created: 2016-07-31T18:53:15.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2021-08-14T18:05:49.000Z (about 3 years ago)
- Last Synced: 2024-06-20T12:51:33.586Z (5 months ago)
- Topics: environment, go, golang, golang-tools
- Language: Go
- Size: 8.79 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# envim - Go environment variables for human
![Build status](https://github.com/cuonglm/envim/actions/workflows/ci.yml/badge.svg?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/cuonglm/envim)](https://goreportcard.com/report/github.com/cuonglm/envim)
[![GoDoc](https://godoc.org/github.com/cuonglm/envim?status.svg)](https://godoc.org/github.com/cuonglm/envim)# Why envim?
Just another (better) way for managing environment variables from Go code, but written for human.
# Installation
```sh
go get -u github.com/cuonglm/envim
```# Usage
```go
package mainimport (
"fmt"env "github.com/cuonglm/envim"
)func main() {
// Clean environment variables
env.Clear()// Set a variable
_ = env.Set("foo", "foo")
_ = env.Set("fooo", "")
_ = env.Set("GOPATH", "/home/cuonglm/go")
_ = env.Set("GOROOT", "/home/cuonglm/sources/go")// Get a variable
fmt.Println(env.Get("foo"))
fmt.Println(env.Get("fooo"))// Check environment variable is set
fmt.Println(env.IsSet("foo"))
fmt.Println(env.IsSet("NotSetVar"))// Unset a variable
_ = env.Unset("fooo")// Get all variables into map
fmt.Printf("%+v\n", env.Map())// Like Map(), but variable with prefix only
fmt.Printf("%+v\n", env.MapWithPrefix("GO"))// Update environment variables from a map
// skipped invalid
m := map[string]string{"bar": "bar", "=": "equal"}
env.FromMap(m)
fmt.Printf("%+v\n", env.Map())
}
```Run that file give you:
```sh
$ go run envim_example.go
footrue
false
map[foo:foo GOPATH:/home/cuonglm/go GOROOT:/home/cuonglm/sources/go]
map[GOROOT:/home/cuonglm/sources/go GOPATH:/home/cuonglm/go]
map[foo:foo GOPATH:/home/cuonglm/go GOROOT:/home/cuonglm/sources/go bar:bar]
```# Author
Cuong Manh Le
# License
See [LICENSE](https://github.com/cuonglm/envim/blob/master/LICENSE)