add skip private field

This commit is contained in:
Jay 2018-12-19 11:26:59 +08:00
parent 43bbbb5acb
commit b1a8bce041
2 changed files with 10 additions and 2 deletions

View File

@ -62,11 +62,16 @@ func ToMap(ss interface{}) map[string]interface{} {
smap := make(map[string]interface{})
mtag := regexp.MustCompile(`cc:\"(.+)\"`)
re := regexp.MustCompile(`^[A-Z]`)
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
tag := string(t.Type().Field(i).Tag)
str := mtag.FindStringSubmatch(tag)
name := t.Type().Field(i).Name
if !re.Match([]byte(name)) {
continue
}
leveling := false
if len(str) > 1 {
strArr := strings.Split(str[1], ",")

View File

@ -11,13 +11,14 @@ type Commands struct {
Message string `db:"message" cc:"message"`
Group string `db:"group" cc:"group"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"mtime"`
}
// CommandsWithGroup -
type CommandsWithGroup struct {
Commands `cc:"-,<<"`
GroupName string `db:"group_name" cc:"group_name"`
private string
}
func TestToMap(t *testing.T) {
@ -31,8 +32,10 @@ func TestToMap(t *testing.T) {
cmdWGroup := CommandsWithGroup{}
cmdWGroup.Commands = cmd
cmdWGroup.GroupName = "asd"
cmdWGroup.private = "123"
ToMap(cmdWGroup)
m := ToMap(cmdWGroup)
t.Log(m)
}
func TestCalcPage(t *testing.T) {