33 lines
552 B
Go
33 lines
552 B
Go
package environment
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// exported functions
|
|
func New(name string, defaultValue string) EnvironmentVariable {
|
|
environmentVariable := EnvironmentVariable{
|
|
Key: name,
|
|
Default: defaultValue,
|
|
Value: func() string {
|
|
if len(name) == 0 {
|
|
return defaultValue
|
|
}
|
|
value := os.Getenv(name)
|
|
if len(value) == 0 {
|
|
return defaultValue
|
|
}
|
|
return value
|
|
},
|
|
}
|
|
return environmentVariable
|
|
}
|
|
|
|
// structs
|
|
type getValue func() string
|
|
|
|
type EnvironmentVariable struct {
|
|
Key string
|
|
Default string
|
|
Value getValue
|
|
}
|