Created
March 4, 2015 10:35
-
-
Save bytespider/eba786c218bf95041c6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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