From 506552c3a93a9094c96699bdf62c533b5b4f42c6 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 4 Jan 2020 17:19:50 +0800 Subject: [PATCH] example codes update; donator updates --- .../net/ghttp/server/request/exit/exit.go | 18 +++++++++++++++ .../ghttp/server/request/json-xml/test1.go | 15 +++++++++++++ .../request/json-xml/{test.go => test2.go} | 0 .example/os/gsession/storage-file/file.go | 22 ++++++++++--------- .example/os/gsession/storage-memory/memory.go | 22 ++++++++++--------- .../redis-hashtable.go | 22 ++++++++++--------- .example/os/gsession/storage-redis/redis.go | 22 ++++++++++--------- DONATOR.MD | 5 +++++ 8 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 .example/net/ghttp/server/request/exit/exit.go create mode 100644 .example/net/ghttp/server/request/json-xml/test1.go rename .example/net/ghttp/server/request/json-xml/{test.go => test2.go} (100%) diff --git a/.example/net/ghttp/server/request/exit/exit.go b/.example/net/ghttp/server/request/exit/exit.go new file mode 100644 index 000000000..8c4d96188 --- /dev/null +++ b/.example/net/ghttp/server/request/exit/exit.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { + if r.GetInt("type") == 1 { + r.Response.Writeln("john") + } + r.Response.Writeln("smith") + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/request/json-xml/test1.go b/.example/net/ghttp/server/request/json-xml/test1.go new file mode 100644 index 000000000..ace00f388 --- /dev/null +++ b/.example/net/ghttp/server/request/json-xml/test1.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { + r.Response.Writef("name: %v, pass: %v", r.Get("name"), r.Get("pass")) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/request/json-xml/test.go b/.example/net/ghttp/server/request/json-xml/test2.go similarity index 100% rename from .example/net/ghttp/server/request/json-xml/test.go rename to .example/net/ghttp/server/request/json-xml/test2.go diff --git a/.example/os/gsession/storage-file/file.go b/.example/os/gsession/storage-file/file.go index f8662135a..83cb57510 100644 --- a/.example/os/gsession/storage-file/file.go +++ b/.example/os/gsession/storage-file/file.go @@ -12,16 +12,18 @@ func main() { s.SetConfigWithMap(g.Map{ "SessionMaxAge": time.Minute, }) - s.BindHandler("/set", func(r *ghttp.Request) { - r.Session.Set("time", gtime.Second()) - r.Response.Write("ok") - }) - s.BindHandler("/get", func(r *ghttp.Request) { - r.Response.Write(r.Session.Map()) - }) - s.BindHandler("/del", func(r *ghttp.Request) { - r.Session.Clear() - r.Response.Write("ok") + s.Group("/", func(group *ghttp.RouterGroup) { + group.ALL("/set", func(r *ghttp.Request) { + r.Session.Set("time", gtime.Timestamp()) + r.Response.Write("ok") + }) + group.ALL("/get", func(r *ghttp.Request) { + r.Response.Write(r.Session.Map()) + }) + group.ALL("/del", func(r *ghttp.Request) { + r.Session.Clear() + r.Response.Write("ok") + }) }) s.SetPort(8199) s.Run() diff --git a/.example/os/gsession/storage-memory/memory.go b/.example/os/gsession/storage-memory/memory.go index 78697f99e..8d956c989 100644 --- a/.example/os/gsession/storage-memory/memory.go +++ b/.example/os/gsession/storage-memory/memory.go @@ -14,16 +14,18 @@ func main() { "SessionMaxAge": time.Minute, "SessionStorage": gsession.NewStorageMemory(), }) - s.BindHandler("/set", func(r *ghttp.Request) { - r.Session.Set("time", gtime.Second()) - r.Response.Write("ok") - }) - s.BindHandler("/get", func(r *ghttp.Request) { - r.Response.Write(r.Session.Map()) - }) - s.BindHandler("/del", func(r *ghttp.Request) { - r.Session.Clear() - r.Response.Write("ok") + s.Group("/", func(group *ghttp.RouterGroup) { + group.ALL("/set", func(r *ghttp.Request) { + r.Session.Set("time", gtime.Timestamp()) + r.Response.Write("ok") + }) + group.ALL("/get", func(r *ghttp.Request) { + r.Response.Write(r.Session.Map()) + }) + group.ALL("/del", func(r *ghttp.Request) { + r.Session.Clear() + r.Response.Write("ok") + }) }) s.SetPort(8199) s.Run() diff --git a/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go b/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go index 3c1b8530a..2e35f89ca 100644 --- a/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go +++ b/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go @@ -14,16 +14,18 @@ func main() { "SessionMaxAge": time.Minute, "SessionStorage": gsession.NewStorageRedisHashTable(g.Redis()), }) - s.BindHandler("/set", func(r *ghttp.Request) { - r.Session.Set("time", gtime.Second()) - r.Response.Write("ok") - }) - s.BindHandler("/get", func(r *ghttp.Request) { - r.Response.Write(r.Session.Map()) - }) - s.BindHandler("/del", func(r *ghttp.Request) { - r.Session.Clear() - r.Response.Write("ok") + s.Group("/", func(group *ghttp.RouterGroup) { + group.ALL("/set", func(r *ghttp.Request) { + r.Session.Set("time", gtime.Timestamp()) + r.Response.Write("ok") + }) + group.ALL("/get", func(r *ghttp.Request) { + r.Response.Write(r.Session.Map()) + }) + group.ALL("/del", func(r *ghttp.Request) { + r.Session.Clear() + r.Response.Write("ok") + }) }) s.SetPort(8199) s.Run() diff --git a/.example/os/gsession/storage-redis/redis.go b/.example/os/gsession/storage-redis/redis.go index 16bbbe2c0..9dbcc4a4d 100644 --- a/.example/os/gsession/storage-redis/redis.go +++ b/.example/os/gsession/storage-redis/redis.go @@ -14,16 +14,18 @@ func main() { "SessionMaxAge": time.Minute, "SessionStorage": gsession.NewStorageRedis(g.Redis()), }) - s.BindHandler("/set", func(r *ghttp.Request) { - r.Session.Set("time", gtime.Second()) - r.Response.Write("ok") - }) - s.BindHandler("/get", func(r *ghttp.Request) { - r.Response.Write(r.Session.Map()) - }) - s.BindHandler("/del", func(r *ghttp.Request) { - r.Session.Clear() - r.Response.Write("ok") + s.Group("/", func(group *ghttp.RouterGroup) { + group.ALL("/set", func(r *ghttp.Request) { + r.Session.Set("time", gtime.Timestamp()) + r.Response.Write("ok") + }) + group.ALL("/get", func(r *ghttp.Request) { + r.Response.Write(r.Session.Map()) + }) + group.ALL("/del", func(r *ghttp.Request) { + r.Session.Clear() + r.Response.Write("ok") + }) }) s.SetPort(8199) s.Run() diff --git a/DONATOR.MD b/DONATOR.MD index 743a6d2bc..5e361491c 100644 --- a/DONATOR.MD +++ b/DONATOR.MD @@ -1,5 +1,7 @@ # Donators +We currently accept donation by Alipay/WechatPay, please note your github/gitee account in your payment bill. + | Name | Channel | Amount | Comment |---|---|--- | --- @@ -37,6 +39,9 @@ |R*s|wechat|¥18.88| 谢谢GF!辛苦了! |粟*e|wechat|¥50.00| |[李超](https://github.com/effortlee)|wechat|¥124.00| +|张炳贤|wechat+qq|¥600.00| +|[王哈哈](https://gitee.com/develop1024)|wechat|¥6.66| 希望gf越来越好 +|夕景|alipay+qq|¥9.96+3.57|