nginx-ui/internal/cosy/map2struct/map2struct.go
2024-04-30 10:11:51 +08:00

25 lines
526 B
Go

package map2struct
import (
"github.com/mitchellh/mapstructure"
)
func WeakDecode(input, output interface{}) error {
config := &mapstructure.DecoderConfig{
Metadata: nil,
Result: output,
WeaklyTypedInput: true,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
ToDecimalHookFunc(), ToTimeHookFunc(), ToNullableStringHookFunc(),
ToTimePtrHookFunc(),
),
TagName: "json",
}
decoder, err := mapstructure.NewDecoder(config)
if err != nil {
return err
}
return decoder.Decode(input)
}