Skip to content

Instantly share code, notes, and snippets.

@bytespider
Created March 4, 2015 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytespider/eba786c218bf95041c6a to your computer and use it in GitHub Desktop.
Save bytespider/eba786c218bf95041c6a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/", Home)
cars := r.Path("/cars").Subrouter()
cars.Methods("GET").HandlerFunc(CarCollection)
cars.Methods("POST").HandlerFunc(CarCreate)
car := r.Path("/cars/{id}").Subrouter()
car.Methods("GET").HandlerFunc(CarRead)
car.Methods("POST").HandlerFunc(CarUpdate)
car.Methods("DELETE").HandlerFunc(CarDelete)
carSpecs := r.Path("/cars/{id}/specs").Subrouter()
carSpecs.Methods("GET").HandlerFunc(CarSpecCollection)
carSpecs.Methods("POST").HandlerFunc(CarSpecCreate)
carSpec := r.Path("/cars/{id}/specs/{section}").Subrouter()
carSpec.Methods("GET").HandlerFunc(CarSpecRead)
carSpec.Methods("PUT", "POST").HandlerFunc(CarSpecUpdate)
carSpec.Methods("DELETE").HandlerFunc(CarSpecDelete)
fmt.Println("Starting server on :3000")
http.ListenAndServe(":3000", r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment