Documentation ¶
Overview ¶
Package util provides utility functions for the rest of the project.
Package util provides utility functions.
Index ¶
- func Dump(v any) error
- func DumpToEnv(file *os.File, content map[string]string, rawValue bool) error
- func DumpToJSON(file *os.File, content map[string]string) error
- func DumpToYAML(file *os.File, content map[string]string) error
- func GenerateUUID() string
- func GetValidator() *validator.Validate
- func GetZeroControlChar() string
- func ParseContent(ctx context.Context, format string, r io.Reader) (map[string]any, error)
- func ParseFile(ctx context.Context, file *os.File) (map[string]any, error)
- func ParseFromText(ctx context.Context, format string, data string) (map[string]any, error)
- func Process(v any) error
- func SetDefault(v any) error
- func SetEnv(v any) error
- func SetID(v any) error
- type Func
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dump ¶ added in v1.1.0
Dump the configuration from the environment variables into `v`. It: - Set values from environment variables using the `env` field tag. - Set default values using the `default` field tag. - Validating the values using the `validate` field tag.
Order of operations: 1. Set default values 2. Set values from environment variables 3. Validate values
NOTE: `v` must be a pointer to a struct. NOTE: It only sets default values for fields that are not set. NOTE: It'll set the value from env vars even if it's not empty (precedence).
NOTE: Like the built-in `json` tag, it'll ignore the field if it isn't exported, and if tag is set to `-`.
func DumpToJSON ¶ added in v1.1.6
DumpToJSON dumps `finalValue` to a `configurer.json` file.
func DumpToYAML ¶ added in v1.1.6
DumpToYAML dumps `finalValue` to a `configurer.yaml` file.
func GenerateUUID ¶ added in v1.1.16
func GenerateUUID() string
GenerateUUID generates a RFC4122 UUID and DCE 1.1: Authentication and Security Services.
func GetValidator ¶ added in v1.1.4
func GetValidator() *validator.Validate
GetValidator returns the validator instance. Use that, for example, to add custom validators.
func GetZeroControlChar ¶ added in v1.1.26
func GetZeroControlChar() string
GetZeroControlChar returns the zero control character used to set the default value of a field. It's needed because if the tag is empty, there's no way to know if the user wants to set the field to the default value or if the field is not set. Set CONFIGURER_ZERO_CONTROL_CHAR to change the default value which is "zero".
func ParseContent ¶ added in v1.3.22
ParseContent parses the string data in .env format.
func ParseFromText ¶ added in v1.3.22
ParseFromText parses the string data in .env format.
func Process ¶ added in v1.1.26
Process `v`: - Set default values using the `default` field tag. - Set values from environment variables using the `env` field tag. - Validating the values using the `validate` field tag.
Order of operations: 1. Set default values 2. Set values from environment variables 3. Validate values
NOTE: `v` must be a pointer to a struct. NOTE: It only sets default values for fields that are not set. NOTE: It'll set the value from env vars even if it's not empty (precedence).
NOTE: Like the built-in `json` tag, it'll ignore the field if it isn't exported, and if tag is set to `-`.
func SetDefault ¶ added in v1.1.2
SetDefault For a given struct `v`, set default values based on the struct field tags (`default`).
NOTE: It only sets default values for fields that are not set.
NOTE: Like the built-in `json` tag, it'll ignore the field if it isn't exported, and if tag is set to `-`.
func SetEnv ¶ added in v1.1.2
SetEnv For a given struct `v`, set values based on the struct field tags (`env`) and the environment variables.
WARN: It will set the value of the field even if it's not empty.
NOTE: Like the built-in `json` tag, it'll ignore the field if it isn't exported, and if tag is set to `-`.
func SetID ¶ added in v1.1.16
SetID For a given struct `v`, set field with the specified ID type.
NOTE: Currently only UUID is supported.
NOTE: It only sets default values for fields that are not set.
NOTE: Like the built-in `json` tag, it'll ignore the field if it isn't exported, and if tag is set to `-`.