Documentation
¶
Index ¶
- func GetBoolEnvOrDefault(env string, defaultValue bool) bool
- func GetEnvOrDefault(env string, defaultValue string) string
- func GetRequiredBoolEnv(key string) bool
- func GetRequiredEnv(key string) string
- func GetRequiredFloat64Env(key string) float64
- func GetRequiredInt64Env(key string) int64
- func GetRequiredIntEnv(key string) int
- func StructValidation(target interface{}, setting ...ValidationSetting) error
- func ToIntOrElse(value *string, defaultValue int) *int
- func ToIntOrElseNil(value *string) *int
- func UserHomePathFix(path string) (string, error)
- type RTranslation
- type RValidation
- type ValidationSetting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBoolEnvOrDefault ¶
GetBoolEnvOrDefault retrieves a boolean environment variable value or returns a default. It converts the environment variable string value to a boolean, considering "true" (case-insensitive) as true and all other values as false.
Parameters:
- env: The name of the environment variable to retrieve
- defaultValue: The default boolean value to return if the environment variable is not set or empty
Returns:
- The boolean value of the environment variable if set and not empty
- The defaultValue if the environment variable is not set or empty
func GetEnvOrDefault ¶
GetEnvOrDefault retrieves the value of an environment variable. If the environment variable is not set or is empty, it returns the provided default value.
Parameters:
- env: The name of the environment variable to retrieve.
- defaultValue: The default value to return if the environment variable is not set or is empty.
Returns:
- The value of the environment variable if it is set and not empty.
- The defaultValue if the environment variable is not set or is empty.
Example Usage:
// Load the "API_KEY" environment variable, defaulting to "defaultKey123" if not set.
apiKey := GetEnvOrDefault("API_KEY", "defaultKey123")
fmt.Println("API Key:", apiKey)
func GetRequiredBoolEnv ¶
GetRequiredBoolEnv retrieves a required boolean environment variable value. If the environment variable is not set, empty, or cannot be converted to a boolean, it logs a fatal error and exits the program.
Parameters:
- key: The name of the required boolean environment variable
Returns:
- The boolean value of the environment variable
Exits with log.Fatal if the environment variable is invalid
func GetRequiredEnv ¶
GetRequiredEnv retrieves a required environment variable value. If the environment variable is not set or empty, it logs a fatal error and exits the program.
Parameters:
- key: The name of the required environment variable
Returns:
- The value of the environment variable if set and not empty
Exits with log.Fatal if the environment variable is not set or empty
func GetRequiredFloat64Env ¶
GetRequiredFloat64Env retrieves a required 64-bit floating-point environment variable value. If the environment variable is not set, empty, or cannot be converted to a float64, it logs a fatal error and exits the program.
Parameters:
- key: The name of the required float64 environment variable
Returns:
- The float64 value of the environment variable
Exits with log.Fatal if the environment variable is invalid
func GetRequiredInt64Env ¶
GetRequiredInt64Env retrieves a required 64-bit integer environment variable value. If the environment variable is not set, empty, or cannot be converted to an int64, it logs a fatal error and exits the program.
Parameters:
- key: The name of the required int64 environment variable
Returns:
- The int64 value of the environment variable
Exits with log.Fatal if the environment variable is invalid
func GetRequiredIntEnv ¶
GetRequiredIntEnv retrieves a required integer environment variable value. If the environment variable is not set, empty, or cannot be converted to an integer, it logs a fatal error and exits the program.
Parameters:
- key: The name of the required integer environment variable
Returns:
- The integer value of the environment variable
Exits with log.Fatal if the environment variable is invalid
func StructValidation ¶
func StructValidation(target interface{}, setting ...ValidationSetting) error
func ToIntOrElse ¶
func ToIntOrElseNil ¶
func UserHomePathFix ¶
UserHomePathFix resolves a path that starts with '~' to the user's home directory. If the home directory cannot be determined, it logs an error and exits the application. Parameters:
- path: The file path string, potentially starting with '~'.
Returns:
- The resolved file path with '~' replaced by the user's home directory, or the original path if no substitution is needed.
Types ¶
type RTranslation ¶
type RTranslation struct {
Tag string
Message string
Validation func(validator.FieldError) []string
}
func DefaultTranslations ¶
func DefaultTranslations() []RTranslation
type RValidation ¶
type RValidation struct {
Tag string
Validator func(fl validator.FieldLevel) bool
}
func DefaultPasswordValidations ¶
func DefaultPasswordValidations() RValidation
type ValidationSetting ¶
type ValidationSetting struct {
Language string
SpecSeparator string
Translations []RTranslation
Validators []RValidation
}
func Default ¶
func Default() *ValidationSetting