https://github.com/josestg/getenv
A type-safe wrapper for os.Getenv that returns a default value if the environment variable is not set.
https://github.com/josestg/getenv
Last synced: about 1 month ago
JSON representation
A type-safe wrapper for os.Getenv that returns a default value if the environment variable is not set.
- Host: GitHub
- URL: https://github.com/josestg/getenv
- Owner: josestg
- License: apache-2.0
- Created: 2024-02-18T08:47:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-28T12:45:15.000Z (about 1 year ago)
- Last Synced: 2025-01-31T06:47:02.459Z (3 months ago)
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getenv
A type-safe wrapper for `os.Getenv` that returns a default value if the environment variable is not set.
## Installation
```bash
go get github.com/josestg/getenv
```## Usage
```go
package mainimport (
"fmt"
"time""github.com/josestg/getenv"
)func main() {
var (
host = getenv.String("HOST", "0.0.0.0")
ports = getenv.Ints("PORTS", []int{8080, 8081, 8082})
debug = getenv.Bool("DEBUG", false)
threshold = getenv.Float("THRESHOLD", 0.5)
maxBodySize = getenv.Int("MAX_BODY_SIZE", uint64(1<<20)) // 1MB
shutdownTimeout = getenv.Duration("SHUTDOWN_TIMEOUT", 5*time.Second)
whitelistHeaders = getenv.Strings("WHITELIST_HEADERS", []string{"Content-Type", "Content-Length"})
)fmt.Println(
host,
ports,
debug,
threshold,
maxBodySize,
shutdownTimeout,
whitelistHeaders,
)
}
```