gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/KeyAnyValuePair.go (about) 1 package corestr 2 3 import ( 4 "fmt" 5 "strings" 6 7 "gitlab.com/evatix-go/core/constants" 8 "gitlab.com/evatix-go/core/coredata/corejson" 9 "gitlab.com/evatix-go/core/internal/reflectinternal" 10 ) 11 12 type KeyAnyValuePair struct { 13 Key string 14 valueString SimpleStringOnce 15 Value interface{} 16 } 17 18 func (it *KeyAnyValuePair) KeyName() string { 19 return it.Key 20 } 21 22 func (it *KeyAnyValuePair) VariableName() string { 23 return it.Key 24 } 25 26 func (it *KeyAnyValuePair) ValueAny() interface{} { 27 return it.Value 28 } 29 30 func (it *KeyAnyValuePair) IsVariableNameEqual(name string) bool { 31 return it.Key == name 32 } 33 34 func (it KeyAnyValuePair) SerializeMust() (jsonBytes []byte) { 35 return corejson.NewPtr(it).RawMust() 36 } 37 38 func (it *KeyAnyValuePair) Compile() string { 39 return it.String() 40 } 41 42 func (it *KeyAnyValuePair) IsValueNull() bool { 43 return it == nil || reflectinternal.IsNull(it.Value) 44 } 45 46 func (it *KeyAnyValuePair) HasNonNull() bool { 47 return it != nil && reflectinternal.IsNotNull(it.Value) 48 } 49 50 func (it *KeyAnyValuePair) HasValue() bool { 51 return it != nil && reflectinternal.IsNotNull(it.Value) 52 } 53 54 func (it *KeyAnyValuePair) IsValueEmptyString() bool { 55 return it == nil || it.ValueString() == "" 56 } 57 58 func (it *KeyAnyValuePair) IsValueWhitespace() bool { 59 return it == nil || strings.TrimSpace(it.ValueString()) == "" 60 } 61 62 func (it *KeyAnyValuePair) ValueString() string { 63 if it.valueString.IsInitialized() { 64 return it.valueString.String() 65 } 66 67 if it.HasNonNull() { 68 valueString := fmt.Sprintf(constants.SprintValueFormat, it.Value) 69 70 return it. 71 valueString. 72 GetPlusSetOnUninitialized(valueString) 73 } 74 75 return it. 76 valueString. 77 GetPlusSetEmptyOnUninitialized() 78 } 79 80 func (it *KeyAnyValuePair) Serialize() ([]byte, error) { 81 return corejson.Serialize.Raw(it) 82 } 83 84 func (it *KeyAnyValuePair) ParseInjectUsingJson( 85 jsonResult *corejson.Result, 86 ) (*KeyAnyValuePair, error) { 87 err := jsonResult.Unmarshal(it) 88 89 if err != nil { 90 return nil, err 91 } 92 93 return it, nil 94 } 95 96 // ParseInjectUsingJsonMust Panic if error 97 func (it *KeyAnyValuePair) ParseInjectUsingJsonMust( 98 jsonResult *corejson.Result, 99 ) *KeyAnyValuePair { 100 parsed, err := it. 101 ParseInjectUsingJson(jsonResult) 102 103 if err != nil { 104 panic(err) 105 } 106 107 return parsed 108 } 109 110 func (it KeyAnyValuePair) Json() corejson.Result { 111 return corejson.New(it) 112 } 113 114 func (it *KeyAnyValuePair) JsonPtr() *corejson.Result { 115 return corejson.NewPtr(it) 116 } 117 118 func (it *KeyAnyValuePair) AsJsonContractsBinder() corejson.JsonContractsBinder { 119 return it 120 } 121 122 func (it *KeyAnyValuePair) AsJsoner() corejson.Jsoner { 123 return it 124 } 125 126 func (it *KeyAnyValuePair) JsonParseSelfInject( 127 jsonResult *corejson.Result, 128 ) error { 129 _, err := it.ParseInjectUsingJson( 130 jsonResult, 131 ) 132 133 return err 134 } 135 136 func (it *KeyAnyValuePair) AsJsonParseSelfInjector() corejson.JsonParseSelfInjector { 137 return it 138 } 139 140 func (it KeyAnyValuePair) String() string { 141 return fmt.Sprintf( 142 keyValuePrintFormat, 143 it.Key, 144 it.Value) 145 } 146 147 func (it *KeyAnyValuePair) Clear() { 148 if it == nil { 149 return 150 } 151 152 it.Key = "" 153 it.Value = nil 154 it.valueString.Dispose() 155 } 156 157 func (it *KeyAnyValuePair) Dispose() { 158 if it == nil { 159 return 160 } 161 162 it.Clear() 163 }