rrandall91/env

View on GitHub
env.go

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
package env

import (
    "os"
)

// Get returns the value of the environment variable named by the key or the fallback value if the variable is not set.
func Get(key string) string {
    return os.Getenv(key)
}

// GetWithDefault returns the value of the environment variable named by the key or the default value if the variable is not set.
func GetWithDefault(key string, fallback string) string {
    if value, ok := os.LookupEnv(key); ok && value != "" {
        return value
    }

    return fallback
}

// Set sets the value of the environment variable named by the key.
func Set(key string, value string) {
    os.Setenv(key, value)
}