@@ -12,27 +12,27 @@ import (
1212 valueUtils "github.com/ARM-software/golang-utils/utils/value"
1313)
1414
15- func GetUnexportedStructureField (structure interface {} , fieldName string ) interface {} {
15+ func GetUnexportedStructureField (structure any , fieldName string ) any {
1616 return GetStructureField (fetchStructureField (structure , fieldName ))
1717}
1818
19- func GetStructureField (field reflect.Value ) interface {} {
19+ func GetStructureField (field reflect.Value ) any {
2020 if ! field .IsValid () {
2121 return nil
2222 }
2323 return reflect .NewAt (field .Type (), unsafe .Pointer (field .UnsafeAddr ())).Elem ().Interface () //nolint:gosec // this conversion is between types recommended by Go https://cs.opensource.google/go/go/+/master:src/reflect/value.go;l=2445
2424}
25- func SetUnexportedStructureField (structure interface {} , fieldName string , value interface {} ) {
25+ func SetUnexportedStructureField (structure any , fieldName string , value any ) {
2626 SetStructureField (fetchStructureField (structure , fieldName ), value )
2727}
28- func SetStructureField (field reflect.Value , value interface {} ) {
28+ func SetStructureField (field reflect.Value , value any ) {
2929 if ! field .IsValid () {
3030 return
3131 }
3232 reflect .NewAt (field .Type (), unsafe .Pointer (field .UnsafeAddr ())).Elem ().Set (reflect .ValueOf (value )) //nolint:gosec // this conversion is between types recommended by Go https://cs.opensource.google/go/go/+/master:src/reflect/value.go;l=2445
3333}
3434
35- func fetchStructureField (structure interface {} , fieldName string ) reflect.Value {
35+ func fetchStructureField (structure any , fieldName string ) reflect.Value {
3636 return reflect .ValueOf (structure ).Elem ().FieldByName (fieldName )
3737}
3838
@@ -41,13 +41,13 @@ func fetchStructureField(structure interface{}, fieldName string) reflect.Value
4141// If the boolean is false then there is no such field on the structure.
4242// If the boolean is true but the interface stores "" then the field exists but is not set.
4343// If the boolean is true and the interface is not empty, the field exists and is set.
44- func GetStructField (structure interface {} , fieldName string ) (interface {} , bool ) {
44+ func GetStructField (structure any , fieldName string ) (any , bool ) {
4545 Field := fetchStructureField (structure , fieldName )
4646 if ! Field .IsValid () {
4747 return "" , false
4848 }
4949
50- if Field .Type ().Kind () == reflect .Ptr {
50+ if Field .Type ().Kind () == reflect .Pointer {
5151 if Field .IsNil () {
5252 return "" , true
5353 }
@@ -60,7 +60,7 @@ func GetStructField(structure interface{}, fieldName string) (interface{}, bool)
6060// SetStructField attempts to set a field of a structure to the given value
6161// It returns nil or an error, in case the field doesn't exist on the structure
6262// or the value and the field have different types
63- func SetStructField (structure interface {} , fieldName string , value interface {} ) error {
63+ func SetStructField (structure any , fieldName string , value any ) error {
6464 ValueStructure := reflect .ValueOf (structure )
6565 Field := ValueStructure .Elem ().FieldByName (fieldName )
6666 // Test field exists on structure
@@ -86,11 +86,11 @@ func SetStructField(structure interface{}, fieldName string, value interface{})
8686
8787 // helpers for determining whether the field and the value have the same underlying types
8888 valueUnderlyingType := reflect .TypeOf (value )
89- if valueKind == reflect .Ptr {
89+ if valueKind == reflect .Pointer {
9090 valueUnderlyingType = valueUnderlyingType .Elem ()
9191 }
9292 fieldUnderlyingType := Field .Type ()
93- if fieldKind == reflect .Ptr {
93+ if fieldKind == reflect .Pointer {
9494 fieldUnderlyingType = fieldUnderlyingType .Elem ()
9595 }
9696
@@ -99,8 +99,8 @@ func SetStructField(structure interface{}, fieldName string, value interface{})
9999 return commonerrors .Newf (commonerrors .ErrConflict , "conflicting types, field [%v] and value [%v]" , fieldKind , valueKind )
100100 }
101101
102- if fieldKind == reflect .Ptr {
103- if valueKind != reflect .Ptr { // value not ptr, field ptr
102+ if fieldKind == reflect .Pointer {
103+ if valueKind != reflect .Pointer { // value not ptr, field ptr
104104 if Field .IsNil () {
105105 pointerToValue := reflect .New (valueReflectValueWrapper .Type ())
106106 pointerToValue .Elem ().Set (valueReflectValueWrapper )
@@ -110,7 +110,7 @@ func SetStructField(structure interface{}, fieldName string, value interface{})
110110 }
111111 }
112112 } else { // field not ptr, val ptr
113- if valueKind == reflect .Ptr {
113+ if valueKind == reflect .Pointer {
114114 Field .Set (valueReflectValueWrapper .Elem ())
115115 }
116116 }
@@ -120,7 +120,7 @@ func SetStructField(structure interface{}, fieldName string, value interface{})
120120
121121// InheritsFrom uses reflection to find if a struct "inherits" from a certain type.
122122// In other words it checks whether the struct embeds a struct of that type.
123- func InheritsFrom (object interface {} , parentType reflect.Type ) bool {
123+ func InheritsFrom (object any , parentType reflect.Type ) bool {
124124 if parentType == nil {
125125 return object == nil
126126 }
@@ -131,7 +131,7 @@ func InheritsFrom(object interface{}, parentType reflect.Type) bool {
131131 return true
132132 }
133133
134- if r .Kind () == reflect .Ptr {
134+ if r .Kind () == reflect .Pointer {
135135 if r .IsNil () {
136136 return false
137137 }
@@ -154,7 +154,7 @@ func InheritsFrom(object interface{}, parentType reflect.Type) bool {
154154 )
155155 kind := parentType .Kind ()
156156 switch kind {
157- case reflect .Ptr :
157+ case reflect .Pointer :
158158 pointerType = parentType
159159 structType = parentType .Elem ()
160160 case reflect .Interface :
@@ -197,7 +197,7 @@ func IsEmpty(value any) bool {
197197}
198198
199199// ToStructPtr returns an instance of the pointer (interface) to the object obj.
200- func ToStructPtr (obj reflect.Value ) (val interface {} , err error ) {
200+ func ToStructPtr (obj reflect.Value ) (val any , err error ) {
201201 if ! obj .IsValid () {
202202 err = commonerrors .Newf (commonerrors .ErrUnsupported , "obj value [%v] is not valid" , obj )
203203 return
0 commit comments