init #1
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module git.whblueocean.cn/blueocean-go/utils
|
||||||
|
|
||||||
|
go 1.25.3
|
||||||
22
tools.go
Normal file
22
tools.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
func GetColumnsFromJsonTag(v interface{}) map[string]bool {
|
||||||
|
columns := make(map[string]bool)
|
||||||
|
t := reflect.TypeOf(v)
|
||||||
|
|
||||||
|
if t.Kind() == reflect.Ptr {
|
||||||
|
t = t.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
field := t.Field(i)
|
||||||
|
jsonTag := field.Tag.Get("json")
|
||||||
|
if jsonTag == "" || jsonTag == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
columns[jsonTag] = true
|
||||||
|
}
|
||||||
|
return columns
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user