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