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/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) } 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) { 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", 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))