We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9485d93 commit ada13f1Copy full SHA for ada13f1
json/README.md
@@ -0,0 +1,13 @@
1
+# goji json sample
2
+
3
+Run server:
4
5
+```
6
+$ go run json.go
7
8
9
+Request to the server:
10
11
12
+curl http://localhost:8000/hello/gopher
13
json/json.go
@@ -0,0 +1,34 @@
+package main
+import (
+ "encoding/json"
+ "net/http"
+ "github.com/zenazn/goji"
+ "github.com/zenazn/goji/web"
+)
+type Hello struct {
+ Name string
+ Msg string
14
+}
15
16
+func hello(c web.C, w http.ResponseWriter, r *http.Request) {
17
+ name := c.URLParams["name"]
18
+ if name == "" {
19
+ name = "gopher"
20
+ }
21
22
+ hello := &Hello{
23
+ Name: name,
24
+ Msg: "Hello",
25
26
27
+ encoder := json.NewEncoder(w)
28
+ encoder.Encode(hello)
29
30
31
+func main() {
32
+ goji.Get("/hello/:name", hello)
33
+ goji.Serve()
34
0 commit comments