File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "encoding/json"
5+ "net/http"
6+
7+ "github.com/zenazn/goji"
8+ "github.com/zenazn/goji/web"
9+ )
10+
11+ type Hello struct {
12+ Name string
13+ 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+ }
You can’t perform that action at this time.
0 commit comments