Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fdbb7c0d77
Fetching contributors…

Cannot retrieve contributors at this time

32 lines (26 sloc) 0.574 kb
package main
import (
"github.com/ant0ine/go-json-rest"
)
type User struct {
Id string
Name string
}
func GetOldAPIUser(w *rest.ResponseWriter, req *rest.Request) {
http.Redirect(w, req.Request, req.UriFor("/users/1"), 302)
}
func GetUser(w *rest.ResponseWriter, req *rest.Request) {
user := User{
Id: req.PathParam("id"),
Name: "Antoine",
}
w.WriteJson(&user)
}
func main() {
handler := rest.ResourceHandler{}
handler.SetRoutes(
rest.Route{"GET", "/user/:id", GetOldAPIUser},
rest.Route{"GET", "/users/:id", GetUser},
)
handler.Start(":8080")
}
Jump to Line
Something went wrong with that request. Please try again.