mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve configuration for gdb; add more unit test case for ghttp.Server
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
|
||||
# MySQL数据库配置
|
||||
[database]
|
||||
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||
debug = true
|
||||
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
func main() {
|
||||
db := g.DB()
|
||||
db.SetDebug(true)
|
||||
//db.SetDebug(true)
|
||||
|
||||
type User struct {
|
||||
Id int
|
||||
|
||||
34
.example/database/gdb/mysql/issue364.go
Normal file
34
.example/database/gdb/mysql/issue364.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"time"
|
||||
)
|
||||
|
||||
func test1() {
|
||||
db := g.DB()
|
||||
db.SetDebug(true)
|
||||
time.Sleep(1 * time.Minute)
|
||||
r, e := db.Table("test").Where("id", 10000).Count()
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
g.Dump(r)
|
||||
}
|
||||
|
||||
func test2() {
|
||||
db := g.DB()
|
||||
db.SetDebug(true)
|
||||
dao := db.Table("test").Safe()
|
||||
time.Sleep(1 * time.Minute)
|
||||
r, e := dao.Where("id", 10000).Count()
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
g.Dump(r)
|
||||
}
|
||||
|
||||
func main() {
|
||||
test1()
|
||||
test2()
|
||||
}
|
||||
@ -344,9 +344,9 @@ func (bs *dbBase) getSqlDb(master bool) (sqlDb *sql.DB, err error) {
|
||||
}
|
||||
|
||||
if bs.maxConnLifetime > 0 {
|
||||
sqlDb.SetConnMaxLifetime(time.Duration(bs.maxConnLifetime) * time.Second)
|
||||
sqlDb.SetConnMaxLifetime(bs.maxConnLifetime * time.Second)
|
||||
} else if node.MaxConnLifetime > 0 {
|
||||
sqlDb.SetConnMaxLifetime(time.Duration(node.MaxConnLifetime) * time.Second)
|
||||
sqlDb.SetConnMaxLifetime(node.MaxConnLifetime * time.Second)
|
||||
}
|
||||
return sqlDb
|
||||
}, 0)
|
||||
|
||||
@ -543,9 +543,7 @@ func (bs *dbBase) doUpdate(link dbLink, table string, data interface{}, conditio
|
||||
}
|
||||
params := []interface{}(nil)
|
||||
switch kind {
|
||||
case reflect.Map:
|
||||
fallthrough
|
||||
case reflect.Struct:
|
||||
case reflect.Map, reflect.Struct:
|
||||
var fields []string
|
||||
for k, v := range structToMap(data) {
|
||||
fields = append(fields, bs.db.quoteWord(k)+"=?")
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
|
||||
const (
|
||||
gFRAME_CORE_COMPONENT_NAME_REDIS = "gf.core.component.redis"
|
||||
gFRAME_CORE_COMPONENT_NAME_GKVDB = "gf.core.component.gkvdb"
|
||||
gFRAME_CORE_COMPONENT_NAME_DATABASE = "gf.core.component.database"
|
||||
)
|
||||
|
||||
@ -160,66 +159,13 @@ func parseDBConfigNode(value interface{}) *gdb.ConfigNode {
|
||||
return nil
|
||||
}
|
||||
node := &gdb.ConfigNode{}
|
||||
if value, ok := nodeMap["host"]; ok {
|
||||
node.Host = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["port"]; ok {
|
||||
node.Port = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["user"]; ok {
|
||||
node.User = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["pass"]; ok {
|
||||
node.Pass = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["name"]; ok {
|
||||
node.Name = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["type"]; ok {
|
||||
node.Type = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["role"]; ok {
|
||||
node.Role = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["debug"]; ok {
|
||||
node.Debug = gconv.Bool(value)
|
||||
}
|
||||
if value, ok := nodeMap["charset"]; ok {
|
||||
node.Charset = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["weight"]; ok {
|
||||
node.Weight = gconv.Int(value)
|
||||
}
|
||||
if value, ok := nodeMap["linkinfo"]; ok {
|
||||
node.LinkInfo = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["link-info"]; ok {
|
||||
node.LinkInfo = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["linkInfo"]; ok {
|
||||
node.LinkInfo = gconv.String(value)
|
||||
err := gconv.Struct(nodeMap, node)
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
}
|
||||
if value, ok := nodeMap["link"]; ok {
|
||||
node.LinkInfo = gconv.String(value)
|
||||
}
|
||||
if value, ok := nodeMap["max-idle"]; ok {
|
||||
node.MaxIdleConnCount = gconv.Int(value)
|
||||
}
|
||||
if value, ok := nodeMap["maxIdle"]; ok {
|
||||
node.MaxIdleConnCount = gconv.Int(value)
|
||||
}
|
||||
if value, ok := nodeMap["max-open"]; ok {
|
||||
node.MaxOpenConnCount = gconv.Int(value)
|
||||
}
|
||||
if value, ok := nodeMap["maxOpen"]; ok {
|
||||
node.MaxOpenConnCount = gconv.Int(value)
|
||||
}
|
||||
if value, ok := nodeMap["max-lifetime"]; ok {
|
||||
node.MaxConnLifetime = gconv.Duration(value)
|
||||
}
|
||||
if value, ok := nodeMap["maxLifetime"]; ok {
|
||||
node.MaxConnLifetime = gconv.Duration(value)
|
||||
}
|
||||
// Parse link syntax.
|
||||
if node.LinkInfo != "" && node.Type == "" {
|
||||
match, _ := gregex.MatchString(`([a-z]+):(.+)`, node.LinkInfo)
|
||||
|
||||
64
net/ghttp/ghttp_unit_router_object_rest2_test.go
Normal file
64
net/ghttp/ghttp_unit_router_object_rest2_test.go
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package ghttp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
"github.com/gogf/gf/test/gtest"
|
||||
)
|
||||
|
||||
type ObjectRest2 struct{}
|
||||
|
||||
func (o *ObjectRest2) Init(r *ghttp.Request) {
|
||||
r.Response.Write("1")
|
||||
}
|
||||
|
||||
func (o *ObjectRest2) Shut(r *ghttp.Request) {
|
||||
r.Response.Write("2")
|
||||
}
|
||||
|
||||
func (o *ObjectRest2) Get(r *ghttp.Request) {
|
||||
r.Response.Write("Object Get", r.Get("id"))
|
||||
}
|
||||
|
||||
func (o *ObjectRest2) Put(r *ghttp.Request) {
|
||||
r.Response.Write("Object Put", r.Get("id"))
|
||||
}
|
||||
|
||||
func (o *ObjectRest2) Post(r *ghttp.Request) {
|
||||
r.Response.Write("Object Post", r.Get("id"))
|
||||
}
|
||||
|
||||
func (o *ObjectRest2) Delete(r *ghttp.Request) {
|
||||
r.Response.Write("Object Delete", r.Get("id"))
|
||||
}
|
||||
|
||||
func Test_Router_ObjectRest_Id(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.BindObjectRest("/object/:id", new(ObjectRest2))
|
||||
s.SetPort(p)
|
||||
s.SetDumpRouteMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.Case(t, func() {
|
||||
client := ghttp.NewClient()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
gtest.Assert(client.GetContent("/object/99"), "1Object Get992")
|
||||
gtest.Assert(client.PutContent("/object/99"), "1Object Put992")
|
||||
gtest.Assert(client.PostContent("/object/99"), "1Object Post992")
|
||||
gtest.Assert(client.DeleteContent("/object/99"), "1Object Delete992")
|
||||
})
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
package gstr_test
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
@ -18,6 +19,17 @@ import (
|
||||
|
||||
func Test_Parse(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
// url
|
||||
gtest.Case(t, func() {
|
||||
s := "goframe.org/index?name=john&score=100"
|
||||
u, err := url.Parse(s)
|
||||
gtest.Assert(err, nil)
|
||||
m, err := gstr.Parse(u.RawQuery)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(m["name"], "john")
|
||||
gtest.Assert(m["score"], "100")
|
||||
})
|
||||
|
||||
// name overwrite
|
||||
m, err := gstr.Parse("a=1&a=2")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
Reference in New Issue
Block a user