Documentation ¶
Index ¶
Constants ¶
View Source
const SensitiveDataMaskString = "***************"
Variables ¶
This section is empty.
Functions ¶
func ParseEnv ¶ added in v0.9.0
func ParseEnv(config interface{}) error
ParseEnv parse the env values to given struct fields env variables are defined using struct tags. It utilizes the "github.com/caarlos0/env/v11" package for parse.
Parameters:
- config (interface{}): The struct to be populated by env variables. The struct should have env variables defined using tags such as `env:"USERNAME"`.
Returns:
- error: Returns nil if the struct created using env variables. if fails, it returns an error which provides details information about the error
Usage Example:
type Config struct { Name string `env:"MY_NAME"` Age int `env:"MY_AGE"` } var conf Config if err := Register(&conf); err != nil { // Handle env pass error, e.g., log or return }
Note:
- The function will panic if the `config` parameter is not a pointer to struct
More env package information https://github.com/caarlos0/env/v11
func StructValidator ¶ added in v0.8.0
func StructValidator(config interface{}) error
StructValidator validates a struct's fields against the validation rules defined using struct tags. It utilizes the "github.com/go-playground/validator/v10" package for validation.
Parameters:
- config (interface{}): The struct to be validated. The struct should have validation rules defined using tags such as `validate:"required"`.
Returns:
- error: Returns nil if the struct passes validation. If validation fails, it returns an error of type `validator.ValidationErrors` which provides detailed information about validation failures.
Usage Example:
type Config struct { Name string `validate:"required"` Age int `validate:"gte=0"` } config := Config{ Name: "", Age: -1, } if err := StructValidator(config); err != nil { // Handle validation errors, e.g., log or return }
Note:
- The validator is initialized with the `WithRequiredStructEnabled` option, which ensures that nil struct fields are treated as invalid.
- The function will panic if the `config` parameter is not a struct or pointer to a struct.
More validator information https://github.com/go-playground/validator
Types ¶
Click to show internal directories.
Click to hide internal directories.