improve gconv.Map for priority tags

This commit is contained in:
John 2019-07-04 14:27:43 +08:00
parent b29c6add47
commit ed61c2ee22
2 changed files with 34 additions and 22 deletions

View File

@ -109,9 +109,9 @@ func Map(value interface{}, tags ...string) map[string]interface{} {
case 0:
// No need handle.
case 1:
tagArray = strings.Split(tags[0], ",")
tagArray = append(strings.Split(tags[0], ","), structTagPriority...)
default:
tagArray = tags
tagArray = append(tags, structTagPriority...)
}
for i := 0; i < rv.NumField(); i++ {
// Only convert the public attributes.

View File

@ -1,28 +1,40 @@
package main
import (
"github.com/gogf/gf/g/os/glog"
"fmt"
"github.com/gogf/gf/g/os/gcache"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/g/encoding/gparser"
)
func localCache() {
result := gcache.GetOrSetFunc("test.key.1", func() interface{} {
return nil
}, 1000*60*2)
if result == nil {
glog.Error("未获取到值")
} else {
glog.Infofln("result is $v", result)
}
}
func TestCache() {
for i := 0; i < 100; i++ {
localCache()
}
}
func main() {
TestCache()
type User struct {
Uid int
Name string
SiteUrl string `gconv:"-"`
NickName string `gconv:"nickname, omitempty"`
Pass1 string `gconv:"password1"`
Pass2 string `gconv:"password2"`
}
g.Dump(gconv.Map(User{
Uid: 100,
Name: "john",
SiteUrl: "https://goframe.org",
Pass1: "123",
Pass2: "456",
}))
s, err := gparser.VarToJsonString(User{
Uid: 100,
Name: "john",
SiteUrl: "https://goframe.org",
Pass1: "123",
Pass2: "456",
})
fmt.Println(err)
fmt.Println(s)
}