@@ -36,7 +36,7 @@ type Field struct {
3636type FieldsInput struct {
3737 // Pointer should be type of struct/*struct.
3838 // TODO this attribute name is not suitable, which would make confuse.
39- Pointer interface {}
39+ Pointer any
4040
4141 // RecursiveOption specifies the way retrieving the fields recursively if the attribute
4242 // is an embedded struct. It is RecursiveOptionNone in default.
@@ -47,7 +47,7 @@ type FieldsInput struct {
4747type FieldMapInput struct {
4848 // Pointer should be type of struct/*struct.
4949 // TODO this attribute name is not suitable, which would make confuse.
50- Pointer interface {}
50+ Pointer any
5151
5252 // PriorityTagArray specifies the priority tag array for retrieving from high to low.
5353 // If it's given `nil`, it returns map[name]Field, of which the `name` is attribute name.
@@ -123,6 +123,7 @@ func Fields(in FieldsInput) ([]Field, error) {
123123 }
124124 }
125125 continue
126+ default :
126127 }
127128 }
128129 continue
@@ -194,6 +195,7 @@ func FieldMap(in FieldMapInput) (map[string]Field, error) {
194195 mapField [k ] = tempV
195196 }
196197 }
198+ default :
197199 }
198200 } else {
199201 mapField [field .Name ()] = tempField
@@ -205,7 +207,19 @@ func FieldMap(in FieldMapInput) (map[string]Field, error) {
205207
206208// StructType retrieves and returns the struct Type of specified struct/*struct.
207209// The parameter `object` should be either type of struct/*struct/[]struct/[]*struct.
208- func StructType (object interface {}) (* Type , error ) {
210+ func StructType (object any ) (* Type , error ) {
211+ // if already reflect.Type
212+ if reflectType , ok := object .(reflect.Type ); ok {
213+ for reflectType .Kind () == reflect .Ptr {
214+ reflectType = reflectType .Elem ()
215+ }
216+ if reflectType .Kind () == reflect .Struct {
217+ return & Type {
218+ Type : reflectType ,
219+ }, nil
220+ }
221+ }
222+
209223 var (
210224 reflectValue reflect.Value
211225 reflectKind reflect.Kind
0 commit comments