Loading Environment Variables
API=123-456-XXX-789func main() {
// Load will read your env file(s) and load them into ENV for this process.
// If you call Load without any args it will default to loading .env in the current path.
err := godotenv.Load()
if err != nil {
// Fatalf is equivalent to [Printf] followed by a call to os.Exit(1)
log.Fatalf("err loading: %v", err)
}
// Get the value of the env variable by passing its variable name
api_key := os.Getenv("API")
}Last updated