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

GetInt

Overview ​

GetInt parses an int environment variable.

Part of the env package — Node.js analog: dotenv / process.env.

Signature ​

go
func GetInt(key string, def int) (int, error)

Compare: Node.js · Standard Go · gox ​

js
// Typical dotenv / process.env pattern in Node.js
go
v := os.Getenv("KEY")
if v == "" {
    v = "default"
}
go
import "github.com/sahilkhaire/gox/env"

port, err := env.GetInt("PORT", 8080)

Example ​

go
import "github.com/sahilkhaire/gox/env"

port, err := env.GetInt("PORT", 8080)

Tips ​

Call Load() once at startup, then use typed getters instead of parsing strings manually.

Standard library alternative ​

Use the standard library directly:

go
v := os.Getenv("KEY")
if v == "" {
    v = "default"
}

← Back to env package overview

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