mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
25 lines
526 B
Go
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)
|
|
}
|