Get
Overview
Get returns the value for key (override, then os.Getenv).
If you are coming from Node.js, the closest pattern is process.env.KEY.
Signature
go
func Get(key string) stringCompare: Node.js · Standard Go · gox
js
const port = process.env.PORT || '8080';go
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}go
import "github.com/sahilkhaire/gox/env"
port := env.Get("PORT")Example
go
import "github.com/sahilkhaire/gox/env"
port := env.Get("PORT")Tips
Call Load() once at startup, then use typed getters instead of parsing strings manually.
Standard library alternative
Use the standard library directly:
go
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}