Files
akvorado/common/helpers/mapstructure.go
Vincent Bernat 8ee2750012 inlet/geoip: rename country-database to geo-database
This is a first step to accept another kind of GeoIP database (like
City). This also introduces the way we want to deprecate stuff:
transform the map structure.
2022-07-29 15:55:39 +02:00

32 lines
986 B
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package helpers
import (
"strings"
"github.com/mitchellh/mapstructure"
)
var mapstructureUnmarshallerHookFuncs = []mapstructure.DecodeHookFunc{}
// AddMapstructureUnmarshallerHook registers a new decoder hook for
// mapstructure. This should only be done during init.
func AddMapstructureUnmarshallerHook(hook mapstructure.DecodeHookFunc) {
mapstructureUnmarshallerHookFuncs = append(mapstructureUnmarshallerHookFuncs, hook)
}
// GetMapStructureUnmarshallerHooks returns all the registered decode
// hooks for mapstructure.
func GetMapStructureUnmarshallerHooks() []mapstructure.DecodeHookFunc {
return mapstructureUnmarshallerHookFuncs
}
// MapStructureMatchName tells if map key and field names are equal.
func MapStructureMatchName(mapKey, fieldName string) bool {
key := strings.ToLower(strings.ReplaceAll(mapKey, "-", ""))
field := strings.ToLower(fieldName)
return key == field
}