This commit is contained in:
John
2018-09-03 10:13:09 +08:00
7 changed files with 20 additions and 20 deletions

View File

@ -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()) }

View File

@ -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)
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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())
}

View File

@ -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",

View File

@ -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))