Split common utility functions into util package (#64)
This commit is contained in:
parent
56ad3dad95
commit
1729399ef9
44 changed files with 177 additions and 193 deletions
24
util/decoder.go
Normal file
24
util/decoder.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// DecodeOther uses mapstructure to decode into target structure. Unused keys cause errors.
|
||||
func DecodeOther(log *Logger, other interface{}, cc interface{}) {
|
||||
decoderConfig := &mapstructure.DecoderConfig{
|
||||
Result: cc,
|
||||
ErrorUnused: true,
|
||||
WeaklyTypedInput: true,
|
||||
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
|
||||
}
|
||||
|
||||
decoder, err := mapstructure.NewDecoder(decoderConfig)
|
||||
if err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
|
||||
if err := decoder.Decode(other); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue