map2struct.go 502 B

123456789101112131415161718192021222324
  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. ),
  13. TagName: "json",
  14. }
  15. decoder, err := mapstructure.NewDecoder(config)
  16. if err != nil {
  17. return err
  18. }
  19. return decoder.Decode(input)
  20. }