add skip private field
This commit is contained in:
parent
43bbbb5acb
commit
b1a8bce041
5
utils.go
5
utils.go
@ -62,11 +62,16 @@ func ToMap(ss interface{}) map[string]interface{} {
|
|||||||
smap := make(map[string]interface{})
|
smap := make(map[string]interface{})
|
||||||
mtag := regexp.MustCompile(`cc:\"(.+)\"`)
|
mtag := regexp.MustCompile(`cc:\"(.+)\"`)
|
||||||
|
|
||||||
|
re := regexp.MustCompile(`^[A-Z]`)
|
||||||
|
|
||||||
for i := 0; i < t.NumField(); i++ {
|
for i := 0; i < t.NumField(); i++ {
|
||||||
f := t.Field(i)
|
f := t.Field(i)
|
||||||
tag := string(t.Type().Field(i).Tag)
|
tag := string(t.Type().Field(i).Tag)
|
||||||
str := mtag.FindStringSubmatch(tag)
|
str := mtag.FindStringSubmatch(tag)
|
||||||
name := t.Type().Field(i).Name
|
name := t.Type().Field(i).Name
|
||||||
|
if !re.Match([]byte(name)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
leveling := false
|
leveling := false
|
||||||
if len(str) > 1 {
|
if len(str) > 1 {
|
||||||
strArr := strings.Split(str[1], ",")
|
strArr := strings.Split(str[1], ",")
|
||||||
|
@ -11,13 +11,14 @@ type Commands struct {
|
|||||||
Message string `db:"message" cc:"message"`
|
Message string `db:"message" cc:"message"`
|
||||||
Group string `db:"group" cc:"group"`
|
Group string `db:"group" cc:"group"`
|
||||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||||
Mtime time.Time `db:"mtime" cc:"ctime"`
|
Mtime time.Time `db:"mtime" cc:"mtime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandsWithGroup -
|
// CommandsWithGroup -
|
||||||
type CommandsWithGroup struct {
|
type CommandsWithGroup struct {
|
||||||
Commands `cc:"-,<<"`
|
Commands `cc:"-,<<"`
|
||||||
GroupName string `db:"group_name" cc:"group_name"`
|
GroupName string `db:"group_name" cc:"group_name"`
|
||||||
|
private string
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToMap(t *testing.T) {
|
func TestToMap(t *testing.T) {
|
||||||
@ -31,8 +32,10 @@ func TestToMap(t *testing.T) {
|
|||||||
cmdWGroup := CommandsWithGroup{}
|
cmdWGroup := CommandsWithGroup{}
|
||||||
cmdWGroup.Commands = cmd
|
cmdWGroup.Commands = cmd
|
||||||
cmdWGroup.GroupName = "asd"
|
cmdWGroup.GroupName = "asd"
|
||||||
|
cmdWGroup.private = "123"
|
||||||
|
|
||||||
ToMap(cmdWGroup)
|
m := ToMap(cmdWGroup)
|
||||||
|
t.Log(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalcPage(t *testing.T) {
|
func TestCalcPage(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user