nginx-ui/api/cosy/map2struct/map2struct.go

24 lines
502 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(),
),
TagName: "json",
}
decoder, err := mapstructure.NewDecoder(config)
if err != nil {
return err
}
return decoder.Decode(input)
}