map2struct.go 526 B

12345678910111213141516171819202122232425
  1. package map2struct
  2. import (
  3. "github.com/mitchellh/mapstructure"
  4. )
  5. func WeakDecode(input, output interface{}) error {
  6. config := &mapstructure.DecoderConfig{
  7. Metadata: nil,
  8. Result: output,
  9. WeaklyTypedInput: true,
  10. DecodeHook: mapstructure.ComposeDecodeHookFunc(
  11. ToDecimalHookFunc(), ToTimeHookFunc(), ToNullableStringHookFunc(),
  12. ToTimePtrHookFunc(),
  13. ),
  14. TagName: "json",
  15. }
  16. decoder, err := mapstructure.NewDecoder(config)
  17. if err != nil {
  18. return err
  19. }
  20. return decoder.Decode(input)
  21. }