zitadel/internal/config/hook/base64_to_bytes.go
2022-05-02 14:41:57 +00:00

27 lines
435 B
Go

package hook
import (
"encoding/base64"
"reflect"
"github.com/mitchellh/mapstructure"
)
func Base64ToBytesHookFunc() mapstructure.DecodeHookFuncType {
return func(
f reflect.Type,
t reflect.Type,
data interface{},
) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf([]byte{}) {
return data, nil
}
return base64.StdEncoding.DecodeString(data.(string))
}
}