Created
July 8, 2014 06:12
-
-
Save hachibeeDI/e4625886286a6651f216 to your computer and use it in GitHub Desktop.
martiniでjsonのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/codegangsta/martini" | |
"github.com/martini-contrib/render" | |
) | |
func main() { | |
m := martini.Classic() | |
m.Use(render.Renderer()) | |
m.Group("/user", func(r martini.Router) { | |
r.Get("/me", GetUserSelf) | |
r.Get("/:id", GetUser) | |
}) | |
m.Run() | |
} | |
func GetUserSelf(r render.Render) { | |
r.JSON( | |
200, | |
map[string]string{ | |
"id": "1", | |
"name": "オグラダイキ", | |
}, | |
) | |
} | |
func GetUser(r render.Render, params martini.Params) { | |
r.JSON( | |
200, | |
map[string]interface{}{ | |
"id": params["id"], | |
"name": "オグラダイキ", | |
}, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment