mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue in gconv.Struct* functions panic when converting attribute value is nil
This commit is contained in:
@ -9,14 +9,14 @@ import (
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/set", func(r *ghttp.Request) {
|
||||
group.GET("/set", func(r *ghttp.Request) {
|
||||
r.Session.Set("time", gtime.Timestamp())
|
||||
r.Response.Write("ok")
|
||||
})
|
||||
g.GET("/get", func(r *ghttp.Request) {
|
||||
group.GET("/get", func(r *ghttp.Request) {
|
||||
r.Response.WriteJson(r.Session.Map())
|
||||
})
|
||||
g.GET("/clear", func(r *ghttp.Request) {
|
||||
group.GET("/clear", func(r *ghttp.Request) {
|
||||
r.Session.Clear()
|
||||
})
|
||||
})
|
||||
29
.example/net/ghttp/server/session/redis/redis.go
Normal file
29
.example/net/ghttp/server/session/redis/redis.go
Normal file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
"github.com/gogf/gf/os/gsession"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.SetSessionMaxAge(2 * time.Minute)
|
||||
s.SetSessionStorage(gsession.NewStorageRedis(g.Redis()))
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.GET("/set", func(r *ghttp.Request) {
|
||||
r.Session.Set("time", gtime.Timestamp())
|
||||
r.Response.Write("ok")
|
||||
})
|
||||
group.GET("/get", func(r *ghttp.Request) {
|
||||
r.Response.WriteJson(r.Session.Map())
|
||||
})
|
||||
group.GET("/clear", func(r *ghttp.Request) {
|
||||
r.Session.Clear()
|
||||
})
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
@ -2,14 +2,35 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
"github.com/gogf/gf/encoding/gjson"
|
||||
)
|
||||
|
||||
func main() {
|
||||
t1 := gconv.Convert(1989, "Time")
|
||||
t2 := gconv.Time("2033-01-11 04:00:00 +0800 CST")
|
||||
fmt.Println(gtime.Timestamp())
|
||||
fmt.Println(t1)
|
||||
fmt.Println(t2)
|
||||
|
||||
type Item struct {
|
||||
Title string `json:"title"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type M struct {
|
||||
Id string `json:"id"`
|
||||
Me map[string]interface{} `json:"me"`
|
||||
Txt string `json:"txt"`
|
||||
Items []*Item `json:"items"`
|
||||
}
|
||||
|
||||
txt := `{
|
||||
"id":"88888",
|
||||
"me":{"name":"mikey","day":"20009"},
|
||||
"txt":"hello",
|
||||
"items":null
|
||||
}`
|
||||
|
||||
json, _ := gjson.LoadContent(txt)
|
||||
fmt.Println(json)
|
||||
m := new(M)
|
||||
e := json.ToStructDeep(m)
|
||||
fmt.Println(e)
|
||||
fmt.Println(m)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user