gitlab.com/evatix-go/core@v1.3.55/coreimpl/enumimpl/KeyAnyVal.go (about) 1 package enumimpl 2 3 import ( 4 "fmt" 5 6 "gitlab.com/evatix-go/core/constants" 7 ) 8 9 type KeyAnyVal struct { 10 Key string 11 AnyValue interface{} 12 } 13 14 func (it KeyAnyVal) KeyString() string { 15 return it.Key 16 } 17 18 func (it KeyAnyVal) AnyVal() interface{} { 19 return it.AnyValue 20 } 21 22 func (it KeyAnyVal) AnyValString() string { 23 return convAnyValToString(it.AnyValue) 24 } 25 26 func (it KeyAnyVal) WrapKey() string { 27 return toJsonName(it.Key) 28 } 29 30 func (it KeyAnyVal) WrapValue() string { 31 return toJsonName(it.AnyValue) 32 } 33 34 func (it KeyAnyVal) IsString() bool { 35 _, isString := it.AnyValue.(string) 36 37 if isString { 38 return true 39 } 40 41 castInt, isInt := it.AnyValue.(int) 42 43 if isInt { 44 return castInt == constants.MinInt 45 } 46 47 return false 48 } 49 50 func (it KeyAnyVal) ValInt() int { 51 return ConvEnumAnyValToInteger(it.AnyValue) 52 } 53 54 func (it KeyAnyVal) KeyValInteger() KeyValInteger { 55 return KeyValInteger{ 56 Key: it.Key, 57 ValueInteger: it.ValInt(), 58 } 59 } 60 61 func (it KeyAnyVal) String() string { 62 if it.IsString() { 63 // stringer 64 return fmt.Sprintf( 65 constants.StringEnumNameValueFormat, 66 it.Key, 67 ) 68 } 69 70 return fmt.Sprintf( 71 constants.EnumNameValueFormat, 72 it.Key, 73 it.AnyValue) 74 }