fast and simple http routing. written in go.
At it's core gogogo is a fast simple http router. It matches requests to handlers by using a Trie data structure. Typically this approach scales well.
As a bonus, gogogo will parse url params as it routes requests.
Best of all gogogo let's you keep your standard http handlers!
func createHandler(w http.ResponseWriter, req *http.Request) {
// ...
}
func idHandler(w http.ResponseWriter, req *http.Request) {
id := req.FormValue("id")
// get :id url param then ...
}
func main() {
// create router instance
r := gogogo.NewRouter()
// let's add a create handler for our resource
r.HandleFunc("/resources/", createHanlder, "POST")
// you can add multiple methods to a handler
r.HandleFunc("/resources/:id", idHandler, "GET", "PUT", "DELETE")
http.ListenAndServe(":8000", r)
}
Great explanation of how to use a trie data structure to write a router in golang.