From a6ff5bd467db5597aa8f6e5da3ab5c2086eafe3c Mon Sep 17 00:00:00 2001 From: john Date: Fri, 31 Aug 2018 10:01:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?gdb.Value=E5=A2=9E=E5=8A=A0IsNil=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/database/gdb/gdb_type_value.go | 1 + geg/util/gvalid/gvalid_struct3.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/g/database/gdb/gdb_type_value.go b/g/database/gdb/gdb_type_value.go index e2481b89e..226701b44 100644 --- a/g/database/gdb/gdb_type_value.go +++ b/g/database/gdb/gdb_type_value.go @@ -11,6 +11,7 @@ import ( "gitee.com/johng/gf/g/util/gconv" ) +func (v Value) IsNil() bool { return v == nil } func (v Value) Bytes() []byte { return []byte(v) } func (v Value) String() string { return string(v.Bytes()) } func (v Value) Bool() bool { return gconv.Bool(v.Bytes()) } diff --git a/geg/util/gvalid/gvalid_struct3.go b/geg/util/gvalid/gvalid_struct3.go index de8b65b52..7ac19f36c 100644 --- a/geg/util/gvalid/gvalid_struct3.go +++ b/geg/util/gvalid/gvalid_struct3.go @@ -10,12 +10,12 @@ import ( func main() { type User struct { Password string `gvalid:"password@password"` - ConfiemPassword string `gvalid:"confirm_password@password|same:password#|密码与确认密码不一致"` + ConfirmPassword string `gvalid:"confirm_password@password|same:password#|密码与确认密码不一致"` } user := &User{ Password : "123456", - ConfiemPassword : "", + ConfirmPassword : "", } gutil.Dump(gvalid.CheckStruct(user, nil)) From 5fcc6d1bee2694de1ac7640a63421c6b9aff88fa Mon Sep 17 00:00:00 2001 From: john Date: Fri, 31 Aug 2018 14:03:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geg/database/orm/mysql/gdb_cache.go | 15 +++------------ geg/database/orm/mysql/gdb_debug.go | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/geg/database/orm/mysql/gdb_cache.go b/geg/database/orm/mysql/gdb_cache.go index 7a64287cc..8ed5a4e5b 100644 --- a/geg/database/orm/mysql/gdb_cache.go +++ b/geg/database/orm/mysql/gdb_cache.go @@ -1,8 +1,8 @@ package main import ( - "fmt" "gitee.com/johng/gf/g/database/gdb" + "gitee.com/johng/gf/g/util/gutil" ) func main() { @@ -26,7 +26,7 @@ func main() { // 执行2次查询并将查询结果缓存3秒,并可执行缓存名称(可选) for i := 0; i < 2; i++ { r, _ := db.Table("user").Cache(3, "vip-user").Where("uid=?", 1).One() - fmt.Println(r.ToMap()) + gutil.Dump(r.ToMap()) } // 执行更新操作,并清理指定名称的查询缓存 @@ -34,14 +34,5 @@ func main() { // 再次执行查询,启用查询缓存特性 r, _ := db.Table("user").Cache(3, "vip-user").Where("uid=?", 1).One() - fmt.Println(r.ToMap()) - - for k, v := range db.GetQueriedSqls() { - fmt.Println(k, ":") - fmt.Println("Sql :", v.Sql) - fmt.Println("Args :", v.Args) - fmt.Println("Error:", v.Error) - fmt.Println("Cost :", v.Cost) - fmt.Println("Func :", v.Func) - } + gutil.Dump(r.ToMap()) } \ No newline at end of file diff --git a/geg/database/orm/mysql/gdb_debug.go b/geg/database/orm/mysql/gdb_debug.go index 1d01f271f..0fffef437 100644 --- a/geg/database/orm/mysql/gdb_debug.go +++ b/geg/database/orm/mysql/gdb_debug.go @@ -11,7 +11,7 @@ func main() { Host: "127.0.0.1", Port: "3306", User: "root", - Pass: "8692651", + Pass: "123456", Name: "test", Type: "mysql", Role: "master", From 32993c37f66ed1473bfff612d13bedd66bde3d8c Mon Sep 17 00:00:00 2001 From: john Date: Fri, 31 Aug 2018 18:46:45 +0800 Subject: [PATCH 3/4] =?UTF-8?q?ghttp.Server=20URL=20path=E4=B8=A5=E8=B0=A8?= =?UTF-8?q?=E6=80=A7=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/net/ghttp/ghttp_server_router_hook.go | 3 +++ g/net/ghttp/ghttp_server_router_serve.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/g/net/ghttp/ghttp_server_router_hook.go b/g/net/ghttp/ghttp_server_router_hook.go index 366fe4310..d97428e4a 100644 --- a/g/net/ghttp/ghttp_server_router_hook.go +++ b/g/net/ghttp/ghttp_server_router_hook.go @@ -84,6 +84,9 @@ func (s *Server) getHookHandlerWithCache(hook string, r *Request) []*handlerPars // 事件方法检索 func (s *Server) searchHookHandler(method, path, domain, hook string) []*handlerParsedItem { + if len(path) == 0 { + return nil + } // 遍历检索的域名列表 domains := []string{ gDEFAULT_DOMAIN } if !strings.EqualFold(gDEFAULT_DOMAIN, domain) { diff --git a/g/net/ghttp/ghttp_server_router_serve.go b/g/net/ghttp/ghttp_server_router_serve.go index 58630d781..c4b5bf395 100644 --- a/g/net/ghttp/ghttp_server_router_serve.go +++ b/g/net/ghttp/ghttp_server_router_serve.go @@ -31,6 +31,9 @@ func (s *Server) getServeHandlerWithCache(r *Request) *handlerParsedItem { // 服务方法检索 func (s *Server) searchServeHandler(method, path, domain string) *handlerParsedItem { + if len(path) == 0 { + return nil + } // 遍历检索的域名列表 domains := []string{ gDEFAULT_DOMAIN } if !strings.EqualFold(gDEFAULT_DOMAIN, domain) { From 786402ca7ebc03b1ded92d9c236c33e46b0eef49 Mon Sep 17 00:00:00 2001 From: john Date: Fri, 31 Aug 2018 18:51:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?ghttp.Request=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=94=A8=E6=88=B7=E7=9C=9F=E5=AE=9EIP=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/net/ghttp/ghttp_request.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/g/net/ghttp/ghttp_request.go b/g/net/ghttp/ghttp_request.go index 0ec7cabc6..a7ea33af5 100644 --- a/g/net/ghttp/ghttp_request.go +++ b/g/net/ghttp/ghttp_request.go @@ -168,11 +168,13 @@ func (r *Request) IsAjaxRequest() bool { func (r *Request) GetClientIp() string { ip := r.clientIp.Val() if len(ip) == 0 { - array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr) - if len(array) > 1 { - ip = array[1] - } else { - ip = r.RemoteAddr + if ip = r.Header.Get("X-Real-IP"); ip == "" { + array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr) + if len(array) > 1 { + ip = array[1] + } else { + ip = r.RemoteAddr + } } r.clientIp.Set(ip) }