Skip to content

Commit

Permalink
decode hook funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Feb 16, 2024
1 parent d18256f commit c2bddf5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,17 @@ func (c Config) validateParamValue(key string, param Parameter) error {
// the "mapstructure" tag renamed to "json". To rename a key, use the "json"
// tag. To embed structs, append ",squash" to your tag. For more details and
// docs, see https://pkg.go.dev/github.com/mitchellh/mapstructure.
func (c Config) DecodeInto(target any) error {
func (c Config) DecodeInto(target any, hookFunc ...mapstructure.DecodeHookFunc) error {
dConfig := &mapstructure.DecoderConfig{
WeaklyTypedInput: true,
Result: &target,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
emptyStringToZeroValueHookFunc(),
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToSliceHookFunc(","),
append(
hookFunc,
emptyStringToZeroValueHookFunc(),
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToSliceHookFunc(","),
)...,
),
TagName: "json",
Squash: true,
Expand Down

0 comments on commit c2bddf5

Please sign in to comment.