Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nasermirzaei89/env
Golang Get Environment Variables Package
https://github.com/nasermirzaei89/env
config env environment-variables generics golang package
Last synced: about 1 month ago
JSON representation
Golang Get Environment Variables Package
- Host: GitHub
- URL: https://github.com/nasermirzaei89/env
- Owner: nasermirzaei89
- License: mit
- Created: 2019-07-24T06:37:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-18T16:49:26.000Z (8 months ago)
- Last Synced: 2024-07-31T20:45:05.930Z (4 months ago)
- Topics: config, env, environment-variables, generics, golang, package
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - nasermirzaei89/env - Simple useful package for read environment variables. (Configuration / Standard CLI)
- fucking-awesome-go - nasermirzaei89/env - Simple useful package for read environment variables. (Configuration / Standard CLI)
- awesome-go - nasermirzaei89/env - Simple useful package for read environment variables. (Configuration / Standard CLI)
- awesome-go - nasermirzaei89/env - Simple useful package for read environment variables. (Configuration / Standard CLI)
- awesome-go-extra - env - 07-24T06:37:13Z|2022-08-14T14:29:51Z| (Configuration / Advanced Console UIs)
- awesome-go-with-stars - nasermirzaei89/env - Simple useful package for read environment variables. (Configuration / Standard CLI)
- awesome-go-cn - nasermirzaei89/env
- awesome-go-plus - nasermirzaei89/env - Simple useful package for read environment variables. ![stars](https://img.shields.io/badge/stars-18-blue) (Configuration / Standard CLI)
- awesome-go-plus - nasermirzaei89/env - Simple useful package for read environment variables. (Configuration / Standard CLI)
README
# Env
Golang Get Environment Variables Package
![Build Status](https://github.com/nasermirzaei89/env/actions/workflows/build.yml/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/nasermirzaei89/env)](https://goreportcard.com/report/github.com/nasermirzaei89/env)
[![Codecov](https://codecov.io/gh/nasermirzaei89/env/branch/master/graph/badge.svg)](https://codecov.io/gh/nasermirzaei89/env)
[![Go Reference](https://pkg.go.dev/badge/github.com/nasermirzaei89/env.svg)](https://pkg.go.dev/github.com/nasermirzaei89/env)
[![awesome-go](https://awesome.re/badge.svg)](https://github.com/avelino/awesome-go#configuration)
[![License](https://img.shields.io/github/license/nasermirzaei89/env)](https://raw.githubusercontent.com/nasermirzaei89/env/master/LICENSE)## Install
```sh
go get github.com/nasermirzaei89/env
```## Sample Usage
### With default value
```go
package mainimport (
"fmt""github.com/nasermirzaei89/env"
)func main() {
b := env.GetBool("A", true)
fmt.Println(b) // true (default)f := env.GetFloat64("B", 14.5)
fmt.Println(f) // 14.5 (default)i := env.GetInt("C", 12)
fmt.Println(i) // 12 (default)s := env.GetString("B", "hi")
fmt.Println(s) // hi (default)// Generics
b2 := env.Get("A", true)
fmt.Println(b2) // true (default)f2 := env.Get("B", 14.5)
fmt.Println(f2) // 14.5 (default)i2 := env.Get("C", 12)
fmt.Println(i2) // 12 (default)s2 := env.Get("B", "hi")
fmt.Println(s2) // hi (default)
}
```### Force setting environment
```go
package mainimport (
"fmt""github.com/nasermirzaei89/env"
)func main() {
s := env.MustGetString("HOME")
fmt.Println(s) // /Users/nasermirzaei89s = env.MustGetString("NEW") // panics
// Generics
s2 := env.MustGet[string]("HOME")
fmt.Println(s2) // /Users/nasermirzaei89s2 = env.MustGet[string]("NEW") // panics
}
```## Contributing
You can submit a [new issue](https://github.com/nasermirzaei89/env/issues/new) in
GitHub [issues](https://github.com/nasermirzaei89/env/issues).
Or you can [create a fork](https://help.github.com/articles/fork-a-repo), hack on your fork and when you're done create
a [pull request](https://help.github.com/articles/fork-a-repo#pull-requests), so that the code contribution can get
merged into the main package.