https://github.com/dmitrymomot/go-env
Helpers to work with environment variables.
https://github.com/dmitrymomot/go-env
Last synced: 3 months ago
JSON representation
Helpers to work with environment variables.
- Host: GitHub
- URL: https://github.com/dmitrymomot/go-env
- Owner: dmitrymomot
- License: apache-2.0
- Created: 2021-03-06T11:38:13.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-16T10:09:10.000Z (over 2 years ago)
- Last Synced: 2025-01-11T18:30:05.680Z (4 months ago)
- Language: Go
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-env
[](https://pkg.go.dev/github.com/dmitrymomot/go-env)
[](https://goreportcard.com/report/github.com/dmitrymomot/go-env)
[](https://github.com/dmitrymomot/go-env/actions/workflows/tests.yml)Helpers to work with environment variables.
## Usage Example
```go
package mainimport (
"fmt"
"net/http"
"github.com/dmitrymomot/go-env"
"github.com/go-chi/chi"
)var (
httpPort = env.MustInt("HTTP_PORT") // required env variable, throws fatal error if it empty
healthEndpoint = env.GetString("HEALTH_ENDPOINT", "/health") // optional env variable with fallback value
)func main() {
r := chi.NewRouter()
r.Get(healthEndpoint, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
http.ListenAndServe(fmt.Sprintf(":%d", httpPort), r)
}
```