package main import ( "fmt" "log" "net/http" "github.com/gorilla/mux" ) var db MovieDB func main() { setupDB() router := mux.NewRouter().StrictSlash(true) router.HandleFunc("/", homeLink) router.HandleFunc("/movie", getMovies).Methods("GET") router.HandleFunc("/movie", addMovie).Methods("POST") router.HandleFunc("/movie/{id}", getOneMovie).Methods("GET") router.HandleFunc("/movie/{id}", delOneMovie).Methods("DELETE") router.HandleFunc("/movie/tag/{id}", getTaggedMovies).Methods("GET") router.HandleFunc("/movie/{mid}/tag/{tid}", addTaggedMovie).Methods("POST") router.HandleFunc("/movie/{mid}/tag/{tid}", delTaggedMovie).Methods("DELETE") router.HandleFunc("/tag", getTags).Methods("GET") router.HandleFunc("/tag", addTag).Methods("POST") router.HandleFunc("/tag/{id}", getOneTag).Methods("GET") router.HandleFunc("/tag/{id}", delOneTag).Methods("DELETE") log.Fatal(http.ListenAndServe(":8080", router)) } func setupDB() { db = CreateMemDB() id1, _ := db.CreateMovie("Murder By Death", "tt0074937") id2, _ := db.CreateMovie("Satanic Panic", "tt8510350") id3, _ := db.CreateMovie("Event Horizon", "tt0119081") id4, _ := db.CreateMovie("Shrek", "tt0126029") fmt.Printf("Created %v %v %v %v\n", id1, id2, id3, id4) t1, _ := db.CreateTag("deea") t2, _ := db.CreateTag("steve") t3, _ := db.CreateTag("bad") fmt.Printf("Created tags %v %v %v\n", t1, t2, t3) db.TagMovie(t1.ID, id1.ID) db.TagMovie(t2.ID, id2.ID) db.TagMovie(t3.ID, id3.ID) db.TagMovie(t3.ID, id4.ID) }