fix issue in gring/ghttp

This commit is contained in:
John 2019-08-26 23:51:01 +08:00
parent 2bf9bc98a7
commit a31108e753
3 changed files with 13 additions and 8 deletions

View File

@ -15,13 +15,13 @@ import (
) )
var length = 10000 var length = 10000
var ring = gring.New(length, true) var ringObject = gring.New(length, true)
func BenchmarkRing_Put(b *testing.B) { func BenchmarkRing_Put(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
i := 0 i := 0
for pb.Next() { for pb.Next() {
ring.Put(i) ringObject.Put(i)
i++ i++
} }
}) })
@ -31,7 +31,7 @@ func BenchmarkRing_Next(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
i := 0 i := 0
for pb.Next() { for pb.Next() {
ring.Next() ringObject.Next()
i++ i++
} }
}) })
@ -41,7 +41,7 @@ func BenchmarkRing_Set(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
i := 0 i := 0
for pb.Next() { for pb.Next() {
ring.Set(i) ringObject.Set(i)
i++ i++
} }
}) })
@ -51,7 +51,7 @@ func BenchmarkRing_Len(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
i := 0 i := 0
for pb.Next() { for pb.Next() {
ring.Len() ringObject.Len()
i++ i++
} }
}) })
@ -61,7 +61,7 @@ func BenchmarkRing_Cap(b *testing.B) {
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
i := 0 i := 0
for pb.Next() { for pb.Next() {
ring.Cap() ringObject.Cap()
i++ i++
} }
}) })

View File

@ -202,6 +202,8 @@ func GetServer(name ...interface{}) *Server {
if s := serverMapping.Get(sname); s != nil { if s := serverMapping.Get(sname); s != nil {
return s.(*Server) return s.(*Server)
} }
sessionStorage := gkvdb.Instance(defaultServerConfig.SessionStoragePath)
sessionStorage.SetOptions(gkvdb.DefaultOptions(defaultServerConfig.SessionStoragePath))
s := &Server{ s := &Server{
name: sname, name: sname,
servers: make([]*gracefulServer, 0), servers: make([]*gracefulServer, 0),
@ -212,7 +214,7 @@ func GetServer(name ...interface{}) *Server {
serveCache: gcache.New(), serveCache: gcache.New(),
routesMap: make(map[string][]registeredRouteItem), routesMap: make(map[string][]registeredRouteItem),
sessions: gcache.New(), sessions: gcache.New(),
sessionStorage: gkvdb.New(gkvdb.DefaultOptions(defaultServerConfig.SessionStoragePath)), sessionStorage: sessionStorage,
servedCount: gtype.NewInt(), servedCount: gtype.NewInt(),
logger: glog.New(), logger: glog.New(),
} }

View File

@ -38,7 +38,9 @@ func Test_Params_Struct(t *testing.T) {
if m := r.GetMap(); len(m) > 0 { if m := r.GetMap(); len(m) > 0 {
user := (*User)(nil) user := (*User)(nil)
r.GetToStruct(&user) r.GetToStruct(&user)
r.Response.Write(user.Id, user.Name, user.Pass1, user.Pass2) if user != nil {
r.Response.Write(user.Id, user.Name, user.Pass1, user.Pass2)
}
} }
}) })
s.BindHandler("/struct-valid", func(r *ghttp.Request) { s.BindHandler("/struct-valid", func(r *ghttp.Request) {
@ -62,6 +64,7 @@ func Test_Params_Struct(t *testing.T) {
gtest.Assert(client.GetContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`) gtest.Assert(client.GetContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
gtest.Assert(client.PostContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`) gtest.Assert(client.PostContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
gtest.Assert(client.PostContent("/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`) gtest.Assert(client.PostContent("/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`)
gtest.Assert(client.PostContent("/struct2", ``), ``)
gtest.Assert(client.PostContent("/struct-valid", `id=1&name=john&password1=123&password2=0`), `{"passwd1":{"length":"字段长度为2到20个字符","password3":"密码强度不足"}}`) gtest.Assert(client.PostContent("/struct-valid", `id=1&name=john&password1=123&password2=0`), `{"passwd1":{"length":"字段长度为2到20个字符","password3":"密码强度不足"}}`)
}) })
} }