From a5a0e381bd9a94e57ee7d4cb2293d162c3bd99d4 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 1 Jan 2020 16:45:43 +0800 Subject: [PATCH] add more examples for ghttp.Server --- .example/net/ghttp/server/request/basic.go | 17 +++++++++++++++++ .../net/ghttp/server/request/params/array.go | 15 +++++++++++++++ .../net/ghttp/server/request/params/map.go | 15 +++++++++++++++ .../net/ghttp/server/request/params/repeat.go | 15 +++++++++++++++ .example/net/ghttp/server/request/priority.go | 18 ++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 .example/net/ghttp/server/request/basic.go create mode 100644 .example/net/ghttp/server/request/params/array.go create mode 100644 .example/net/ghttp/server/request/params/map.go create mode 100644 .example/net/ghttp/server/request/params/repeat.go create mode 100644 .example/net/ghttp/server/request/priority.go diff --git a/.example/net/ghttp/server/request/basic.go b/.example/net/ghttp/server/request/basic.go new file mode 100644 index 000000000..d706b6267 --- /dev/null +++ b/.example/net/ghttp/server/request/basic.go @@ -0,0 +1,17 @@ +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.Writeln(r.Get("amount")) + r.Response.Writeln(r.GetInt("amount")) + r.Response.Writeln(r.GetFloat32("amount")) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/request/params/array.go b/.example/net/ghttp/server/request/params/array.go new file mode 100644 index 000000000..ab177bffe --- /dev/null +++ b/.example/net/ghttp/server/request/params/array.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.Write(r.Get("array")) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/request/params/map.go b/.example/net/ghttp/server/request/params/map.go new file mode 100644 index 000000000..476c665a9 --- /dev/null +++ b/.example/net/ghttp/server/request/params/map.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.Write(r.Get("map")) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/request/params/repeat.go b/.example/net/ghttp/server/request/params/repeat.go new file mode 100644 index 000000000..1384ac333 --- /dev/null +++ b/.example/net/ghttp/server/request/params/repeat.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.Write(r.Get("name")) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/request/priority.go b/.example/net/ghttp/server/request/priority.go new file mode 100644 index 000000000..538c77630 --- /dev/null +++ b/.example/net/ghttp/server/request/priority.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("/input", func(r *ghttp.Request) { + r.Response.Writeln(r.Get("amount")) + }) + s.BindHandler("/query", func(r *ghttp.Request) { + r.Response.Writeln(r.GetQuery("amount")) + }) + s.SetPort(8199) + s.Run() +}