go-scan/util/environment/environment.go
2022-06-24 15:31:48 +02:00

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
}