import ( "github.com/go-martini/martini" "github.com/martini-contrib/render" ) func main() { m := martini.Classic() m.Use(render.Renderer()) m.Get("/users", func(r render.Render) { r.JSON(200, []string{"user1", "user2", "user3"}) }) m.Run() }
import ( "encoding/json" "github.com/go-martini/martini" "github.com/martini-contrib/render" ) type User struct { Name string `json:"name"` Email string `json:"email"` } func main() { m := martini.Classic() m.Use(render.Renderer()) m.Get("/users", func(r render.Render) { users := []User{{"user1", "[email protected]"}, {"user2", "[email protected]"}} data, _ := json.Marshal(users) r.JSON(200, data) }) m.Run() }In this example, the render package is used along with the encoding/json package to render a JSON response when the "/users" endpoint is hit. The user data is first Marshaled into JSON and then passed to the JSON function.