diff --git a/.example/other/test.go b/.example/other/test.go index 143fc563f..1207f662d 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -2,18 +2,25 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" "github.com/gogf/gf/os/gtime" "github.com/gogf/gf/util/gconv" ) func main() { - type T struct { - UpdateTime gtime.Time - } - t := new(T) - gconv.Struct(g.Map{ - "UpdateTime": gtime.Now(), - }, t) - fmt.Println(t.UpdateTime) + // select * from table1 where field1='1111' + // and ( + // (field2='2' and field3='3') + // or + // (field2='21' and field3='31') + // or + // (field2='22' and field3='32') + // ) + //g.DB().Table("table1"). + // Where("field1", "1111"). + // And(g.Map{"field2": 2, "field3": 3}) + //fmt.Println(gconv.GTime("2020-01-01 12:01:00").String()) + //t := gconv.Convert("2020-01-01 12:01:00", "gtime.Time").(gtime.Time) + t := gconv.Convert(1989, "gtime.Time").(gtime.Time) + fmt.Println(t.String()) + fmt.Println(gconv.String(t)) } diff --git a/net/ghttp/ghttp_request_middleware.go b/net/ghttp/ghttp_request_middleware.go index 6bb704ce7..f4e4907e9 100644 --- a/net/ghttp/ghttp_request_middleware.go +++ b/net/ghttp/ghttp_request_middleware.go @@ -38,11 +38,12 @@ func (m *Middleware) Next() { m.handlerIndex++ continue } - // Router values switching. - m.request.routerMap = item.values // Current router switching. m.request.Router = item.handler.router + // Router values switching. + m.request.routerMap = item.values + gutil.TryCatch(func() { // Execute bound middleware array of the item if it's not empty. if m.handlerMDIndex < len(item.handler.middleware) { diff --git a/util/gconv/gconv.go b/util/gconv/gconv.go index f694aeb76..54a99ddc3 100644 --- a/util/gconv/gconv.go +++ b/util/gconv/gconv.go @@ -201,11 +201,21 @@ func String(i interface{}) string { return value case []byte: return string(value) + case time.Time: + if value.IsZero() { + return "" + } + return value.String() case *time.Time: if value == nil { return "" } return value.String() + case gtime.Time: + if value.IsZero() { + return "" + } + return value.String() case *gtime.Time: if value == nil { return "" diff --git a/util/gconv/gconv_z_all_test.go b/util/gconv/gconv_z_all_test.go index f94a32453..8a1f577bc 100644 --- a/util/gconv/gconv_z_all_test.go +++ b/util/gconv/gconv_z_all_test.go @@ -637,7 +637,7 @@ func Test_Convert_All(t *testing.T) { gtest.AssertEQ(gconv.Convert("1989-01-02", "Time", "Y-m-d"), gconv.Time("1989-01-02", "Y-m-d")) gtest.AssertEQ(gconv.Convert(1989, "Time"), gconv.Time("1970-01-01 08:33:09 +0800 CST")) gtest.AssertEQ(gconv.Convert(gtime.Now(), "gtime.Time", 1), nil) - gtest.AssertEQ(gconv.Convert(1989, "gtime.Time"), gtime.Time{gconv.Time("1970-01-01 08:33:09 +0800 CST")}) + gtest.AssertEQ(gconv.Convert(1989, "gtime.Time"), *gconv.GTime("1970-01-01 08:33:09 +0800 CST")) gtest.AssertEQ(gconv.Convert(gtime.Now(), "*gtime.Time", 1), nil) gtest.AssertEQ(gconv.Convert(gtime.Now(), "GTime", 1), nil) gtest.AssertEQ(gconv.Convert(1989, "*gtime.Time"), gconv.GTime(1989))