gitlab.com/evatix-go/core@v1.3.55/namevalue/Instance.go (about) 1 package namevalue 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "gitlab.com/evatix-go/core/constants" 8 ) 9 10 type Instance struct { 11 Name string 12 Value interface{} 13 } 14 15 func (it *Instance) IsNull() bool { 16 return it == nil 17 } 18 19 func (it Instance) String() string { 20 if it.IsNull() { 21 return constants.EmptyString 22 } 23 24 return fmt.Sprintf( 25 constants.KeyValShortFormat, 26 it.Name, 27 it.Value) 28 } 29 30 func (it Instance) JsonString() string { 31 if it.IsNull() { 32 return constants.EmptyString 33 } 34 35 rawBytes, err := json.Marshal(it) 36 37 if err != nil || rawBytes == nil { 38 return constants.EmptyString 39 } 40 41 return string(rawBytes) 42 } 43 44 func (it *Instance) Dispose() { 45 if it == nil { 46 return 47 } 48 49 it.Name = constants.EmptyString 50 it.Value = nil 51 }