You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
I think it would be nice if mapstructure would support an unmarshaling interface like for the json module, so custom marshalers can be defined on a per-type basis easily:
typeMyTypestruct {
numberintnumberTimesTwoint
}
// For example we call the interface function for mapstructure UnmarshalMapfunc (t*MyType) UnmarshalMap(valueinterface{}) error {
// Although not a real-world usecase, just multiply our read number by 2.intValue, ok:=value.(int)
if!ok {
returnerrors.New("Can't convert value to int")
}
t.number=valuet.numberTimesTwo=value*2returnnil
}
Specifically I tried to do custom marshaling inside viper, which internally uses mapstructure to unmarshal from its internal map-representation of config-key-values to my config-struct. But there are no possibilities there to "override" marshaling behaviour for my types and I have to write quite some boilerplate to circumvent that^^
veger, jstroem, beornf, LEI, elmerbulthuis and 36 morePythonista7, prashant-shahi, leandrocostam, franchb and wagoodman