diff --git a/geg/database/mysql/mysql.go b/geg/database/mysql/mysql.go index 427548548..c4dadc5cf 100644 --- a/geg/database/mysql/mysql.go +++ b/geg/database/mysql/mysql.go @@ -477,9 +477,7 @@ func mapToStruct() { } func main() { - r, err := db.Table("user").Data([]map[string]interface{}{ - map[string]interface{}{"name" : "john11111"}, - }).Insert() + r, err := db.Table("user").Data(g.Map{"name" : "john11111"}).Insert() fmt.Println(r) fmt.Println(err) //create() diff --git a/geg/net/ghttp/performance/client.go b/geg/net/ghttp/performance/client.go new file mode 100644 index 000000000..175b74b76 --- /dev/null +++ b/geg/net/ghttp/performance/client.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "sync" + "gitee.com/johng/gf/g/os/gtime" + "gitee.com/johng/gf/g/net/ghttp" + "gitee.com/johng/gf/g/container/gtype" +) + +func main() { + clientMax := 10 + requestMax := 1000 + failureNum := gtype.NewInt64() + successNum := gtype.NewInt64() + startTime := gtime.Millisecond() + + wg := sync.WaitGroup{} + for i := 0; i < clientMax; i++ { + wg.Add(1) + go func(clientId int) { + for j := 0; j < requestMax; j++ { + if c, e := ghttp.Get("http://127.0.0.1/"); e == nil { + c.Close() + successNum.Add(1) + } else { + failureNum.Add(1) + } + } + wg.Done() + }(i) + } + wg.Wait() + + fmt.Printf("time spent: %d ms, success:%d, failure: %d\n", + gtime.Millisecond() - startTime, successNum.Val(), failureNum.Val()) +} \ No newline at end of file diff --git a/geg/net/ghttp/performance/gf/dynamic.go b/geg/net/ghttp/performance/gf/dynamic.go new file mode 100644 index 000000000..ed36c83c2 --- /dev/null +++ b/geg/net/ghttp/performance/gf/dynamic.go @@ -0,0 +1,15 @@ +package main + +import ( + "gitee.com/johng/gf/g" + "gitee.com/johng/gf/g/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/dynamic/:name", func(r *ghttp.Request){ + r.Response.Writeln(r.Get("name")) + }) + s.SetPort(8199) + s.Run() +} \ No newline at end of file diff --git a/geg/net/ghttp/performance/gf/static.go b/geg/net/ghttp/performance/gf/static.go new file mode 100644 index 000000000..be6bc7c4f --- /dev/null +++ b/geg/net/ghttp/performance/gf/static.go @@ -0,0 +1,15 @@ +package main + +import ( + "gitee.com/johng/gf/g" + "gitee.com/johng/gf/g/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request){ + r.Response.Writeln("哈喽世界!") + }) + s.SetPort(8199) + s.Run() +} \ No newline at end of file diff --git a/geg/other/test.go b/geg/other/test.go index 1e9dcf4b0..fdcf1f6c8 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -1,16 +1,22 @@ package main import ( - "gitee.com/johng/gf/g" "fmt" + "time" + "gitee.com/johng/gf/g" + "gitee.com/johng/gf/g/os/gproc" ) func main() { - - c := g.Config() - c.SetPath("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/os/gcfg") - c.SetFileName("redis.yml") - fmt.Println(c.Get("redis-cache")) - - -} + if !gproc.IsChild() { + go func() { + for { + fmt.Println("test") + time.Sleep(2 * time.Second) + } + }() + } + s := g.Server() + s.SetPort(9000) + s.Run() +} \ No newline at end of file