github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume2/section2/gopherface/gopherface.go (about) 1 package main 2 3 import ( 4 "net/http" 5 "os" 6 7 "github.com/EngineerKamesh/gofullstack/volume2/section2/gopherface/endpoints" 8 "github.com/EngineerKamesh/gofullstack/volume2/section2/gopherface/handlers" 9 "github.com/EngineerKamesh/gofullstack/volume2/section2/gopherface/middleware" 10 ghandlers "github.com/gorilla/handlers" 11 "github.com/gorilla/mux" 12 ) 13 14 const ( 15 WEBSERVERPORT = ":8080" 16 ) 17 18 func main() { 19 20 r := mux.NewRouter() 21 r.HandleFunc("/", handlers.HomeHandler) 22 r.HandleFunc("/register", handlers.RegisterHandler).Methods("GET,POST") 23 r.HandleFunc("/login", handlers.LoginHandler).Methods("POST") 24 r.HandleFunc("/logout", handlers.LogoutHandler).Methods("POST") 25 r.HandleFunc("/feed", handlers.FeedHandler).Methods("GET") 26 r.HandleFunc("/friends", handlers.FriendsHandler).Methods("GET") 27 r.HandleFunc("/find", handlers.FindHandler).Methods("GET,POST") 28 r.HandleFunc("/profile", handlers.MyProfileHandler).Methods("GET") 29 r.HandleFunc("/profile/{username}", handlers.ProfileHandler).Methods("GET") 30 r.HandleFunc("/triggerpanic", handlers.TriggerPanicHandler).Methods("GET") 31 r.HandleFunc("/foo", handlers.FooHandler).Methods("GET") 32 33 r.HandleFunc("/restapi/socialmediapost/{username}", endpoints.FetchPostsEndpoint).Methods("GET") 34 r.HandleFunc("/restapi/socialmediapost/{postid}", endpoints.CreatePostEndpoint).Methods("POST") 35 r.HandleFunc("/restapi/socialmediapost/{postid}", endpoints.UpdatePostEndpoint).Methods("PUT") 36 r.HandleFunc("/restapi/socialmediapost/{postid}", endpoints.DeletePostEndpoint).Methods("DELETE") 37 38 //http.Handle("/", r) 39 //http.Handle("/", ghandlers.LoggingHandler(os.Stdout, r)) 40 //http.Handle("/", middleware.PanicRecoveryHandler(ghandlers.LoggingHandler(os.Stdout, r))) 41 http.Handle("/", middleware.ContextExampleHandler(middleware.PanicRecoveryHandler(ghandlers.LoggingHandler(os.Stdout, r)))) 42 43 http.ListenAndServe(WEBSERVERPORT, nil) 44 45 }