You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
1 year ago
|
package mapping
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"reflect"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
defaultOption = "default"
|
||
|
envOption = "env"
|
||
|
inheritOption = "inherit"
|
||
|
stringOption = "string"
|
||
|
optionalOption = "optional"
|
||
|
optionsOption = "options"
|
||
|
rangeOption = "range"
|
||
|
optionSeparator = "|"
|
||
|
equalToken = "="
|
||
|
escapeChar = '\\'
|
||
|
leftBracket = '('
|
||
|
rightBracket = ')'
|
||
|
leftSquareBracket = '['
|
||
|
rightSquareBracket = ']'
|
||
|
segmentSeparator = ','
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
errUnsupportedType = errors.New("unsupported type on setting field value")
|
||
|
errNumberRange = errors.New("wrong number range setting")
|
||
|
//optionsCache = make(map[string]optionsCacheValue)
|
||
|
cacheLock sync.RWMutex
|
||
|
//structRequiredCache = make(map[reflect.Type]requiredCacheValue)
|
||
|
structCacheLock sync.RWMutex
|
||
|
)
|
||
|
|
||
|
func Deref(t reflect.Type) reflect.Type {
|
||
|
for t.Kind() == reflect.Ptr {
|
||
|
t = t.Elem()
|
||
|
}
|
||
|
return t
|
||
|
}
|
||
|
func ValidatePtr(v *reflect.Value) error {
|
||
|
if !v.IsValid() || v.Kind() != reflect.Ptr || v.IsNil() {
|
||
|
return fmt.Errorf("not a valid pointer: %v", v)
|
||
|
}
|
||
|
return nil
|
||
|
}
|