Skip to content
Node: process.env.KEYgithub.com/sahilkhaire/gox/env

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) string

Compare: 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"
}

Back to env package overview

MIT Licensed · Built for Node.js developers moving to Go