diff --git a/container/gring/gring_bench_test.go b/container/gring/gring_bench_test.go index c712f4a34..dd9f69b22 100644 --- a/container/gring/gring_bench_test.go +++ b/container/gring/gring_bench_test.go @@ -15,13 +15,13 @@ import ( ) var length = 10000 -var ring = gring.New(length, true) +var ringObject = gring.New(length, true) func BenchmarkRing_Put(b *testing.B) { b.RunParallel(func(pb *testing.PB) { i := 0 for pb.Next() { - ring.Put(i) + ringObject.Put(i) i++ } }) @@ -31,7 +31,7 @@ func BenchmarkRing_Next(b *testing.B) { b.RunParallel(func(pb *testing.PB) { i := 0 for pb.Next() { - ring.Next() + ringObject.Next() i++ } }) @@ -41,7 +41,7 @@ func BenchmarkRing_Set(b *testing.B) { b.RunParallel(func(pb *testing.PB) { i := 0 for pb.Next() { - ring.Set(i) + ringObject.Set(i) i++ } }) @@ -51,7 +51,7 @@ func BenchmarkRing_Len(b *testing.B) { b.RunParallel(func(pb *testing.PB) { i := 0 for pb.Next() { - ring.Len() + ringObject.Len() i++ } }) @@ -61,7 +61,7 @@ func BenchmarkRing_Cap(b *testing.B) { b.RunParallel(func(pb *testing.PB) { i := 0 for pb.Next() { - ring.Cap() + ringObject.Cap() i++ } }) diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index c11e9d1ee..97ecb6eda 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -202,6 +202,8 @@ func GetServer(name ...interface{}) *Server { if s := serverMapping.Get(sname); s != nil { return s.(*Server) } + sessionStorage := gkvdb.Instance(defaultServerConfig.SessionStoragePath) + sessionStorage.SetOptions(gkvdb.DefaultOptions(defaultServerConfig.SessionStoragePath)) s := &Server{ name: sname, servers: make([]*gracefulServer, 0), @@ -212,7 +214,7 @@ func GetServer(name ...interface{}) *Server { serveCache: gcache.New(), routesMap: make(map[string][]registeredRouteItem), sessions: gcache.New(), - sessionStorage: gkvdb.New(gkvdb.DefaultOptions(defaultServerConfig.SessionStoragePath)), + sessionStorage: sessionStorage, servedCount: gtype.NewInt(), logger: glog.New(), } diff --git a/net/ghttp/ghttp_unit_param_struct_test.go b/net/ghttp/ghttp_unit_param_struct_test.go index 6f6ae56b3..fb43b9665 100644 --- a/net/ghttp/ghttp_unit_param_struct_test.go +++ b/net/ghttp/ghttp_unit_param_struct_test.go @@ -38,7 +38,9 @@ func Test_Params_Struct(t *testing.T) { if m := r.GetMap(); len(m) > 0 { user := (*User)(nil) 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) { @@ -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.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", ``), ``) gtest.Assert(client.PostContent("/struct-valid", `id=1&name=john&password1=123&password2=0`), `{"passwd1":{"length":"字段长度为2到20个字符","password3":"密码强度不足"}}`) }) }