Documentation
¶
Index ¶
- Variables
- func DurationBiggerThanZero(a, b time.Duration) bool
- func GetEnvBool(key string, defaultValue bool) bool
- func GetEnvDuration(key string, defaultValue time.Duration) time.Duration
- func GetEnvInt(key string, defaultValue int) int
- func GetEnvString(key string, defaultValue string) string
- func IntABiggerThanB(a, b int) bool
- func IntASmallerThanB(a, b int) bool
- func IntBiggerThanZero(a, b int) bool
- func LoadEnvAll(envFiles ...string)
- func LoadEnvEach(envFiles ...string)
- func ReloadEnvEach(additionalFiles ...string)
- func ValueOrDefault[T comparable](value, preset T, compF ComparisonFunction[T]) T
- type ComparisonFunction
Constants ¶
This section is empty.
Variables ¶
var ( // This is for backward compatibility, once all app using this are upgraded // remove below aliases. These functions are depcrecated and renamed InitEnv func(...string) = LoadEnvEach LoadEnv func(...string) = LoadEnvAll LoadEnvironment func(...string) = ReloadEnvEach GetEnv func(string, string) string = GetEnvString )
Functions ¶
func DurationBiggerThanZero ¶
func GetEnvBool ¶
GetBool retrieves a boolean environment variable or returns a default value
func GetEnvDuration ¶
GetDuration retrieves a duration environment variable or returns a default value
func GetEnvString ¶
GetEnv retrieves an environment variable or returns a default value if not set.
func IntABiggerThanB ¶
func IntASmallerThanB ¶
func LoadEnvAll ¶
func LoadEnvAll(envFiles ...string)
LoadEnvAll loads environment variables from .env file and optional additional files. This will load all the files in the order they are provided, skipping any existing variables with the same name. If a file does not exist, it will be ignored without error. This is the default behavior of godotenv.Load().
func ReloadEnvEach ¶
func ReloadEnvEach(additionalFiles ...string)
LoadEnvironment loads environment variables from .env file and optional additional files. This use the Overload() means it will overwrite the variables if already exist, Load() won't
func ValueOrDefault ¶
func ValueOrDefault[T comparable](value, preset T, compF ComparisonFunction[T]) T
Used to get value usually from environment if value is true via ComparisonFunction use value, if not use preset (or default value) Ex: ValueOrDefault(time.Duration(timeout)*time.Second, DEFAULT_TIMEOUT, DurationBiggerThanZero),
Set with maxIdle if bigger than 0 or use DEFAULT_MAX_IDLE MaxIdleConns = ValueOrDefault(maxIdle, DEFAULT_MAX_IDLE_CONNECTIONS, IntBiggerThanZero),
Set with maxIdle if it's bigger than DEFAULT_MAX_IDLE or use DEFAULT_MAX_IDLE MaxIdleConns = ValueOrDefault(maxIdle, DEFAULT_MAX_IDLE, IntABiggerThanB),
Types ¶
type ComparisonFunction ¶
type ComparisonFunction[T comparable] func(a, b T) bool
This is used for comparing to something, some use only 1 variable (a) sometimes we need 2 variables. Ex: func(a,b) { return a> 0} -- this means if a > 0 then return true . func(a,b) { return a > b} -- this meansi f a > b then return true This is used for comparison ValueOrDefault() function Which if the ComparisonFunction returns true, return a, if not return b