Skip to content

Instantly share code, notes, and snippets.

@hachibeeDI
Created July 8, 2014 06:12
Show Gist options
  • Save hachibeeDI/e4625886286a6651f216 to your computer and use it in GitHub Desktop.
Save hachibeeDI/e4625886286a6651f216 to your computer and use it in GitHub Desktop.
martiniでjsonのサンプル
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