github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume2/section5/gopherfacedb/gopherface.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  
     6  	"github.com/EngineerKamesh/gofullstack/volume2/section5/gopherfacedb/common"
     7  	"github.com/EngineerKamesh/gofullstack/volume2/section5/gopherfacedb/common/datastore"
     8  	"github.com/EngineerKamesh/gofullstack/volume2/section5/gopherfacedb/handlers"
     9  	"github.com/EngineerKamesh/gofullstack/volume2/section5/gopherfacedb/middleware"
    10  
    11  	"net/http"
    12  	"os"
    13  
    14  	ghandlers "github.com/gorilla/handlers"
    15  	"github.com/gorilla/mux"
    16  )
    17  
    18  const (
    19  	WEBSERVERPORT = ":8080"
    20  )
    21  
    22  func main() {
    23  
    24  	db, err := datastore.NewDatastore(datastore.MYSQL, "gopherface:gopherface@/gopherfacedb")
    25  	//db, err := datastore.NewDatastore(datastore.MONGODB, "localhost:27017")
    26  	//db, err := datastore.NewDatastore(datastore.REDIS, "localhost:6379")
    27  
    28  	if err != nil {
    29  		log.Print(err)
    30  	}
    31  
    32  	defer db.Close()
    33  
    34  	env := common.Env{DB: db}
    35  
    36  	r := mux.NewRouter()
    37  	r.HandleFunc("/", handlers.HomeHandler)
    38  	r.HandleFunc("/register", handlers.RegisterHandler).Methods("GET,POST")
    39  	r.HandleFunc("/login", handlers.LoginHandler).Methods("POST")
    40  	r.HandleFunc("/logout", handlers.LogoutHandler).Methods("POST")
    41  	r.HandleFunc("/feed", handlers.FeedHandler).Methods("GET")
    42  	r.HandleFunc("/friends", handlers.FriendsHandler).Methods("GET")
    43  	r.HandleFunc("/find", handlers.FindHandler).Methods("GET,POST")
    44  	r.HandleFunc("/profile", handlers.MyProfileHandler).Methods("GET")
    45  	r.HandleFunc("/profile/{username}", handlers.ProfileHandler)
    46  	r.HandleFunc("/triggerpanic", handlers.TriggerPanicHandler)
    47  	r.HandleFunc("/foo", handlers.FooHandler)
    48  	r.Handle("/signup", handlers.SignUpHandler(&env)).Methods("GET", "POST")
    49  	r.HandleFunc("/postpreview", handlers.PostPreviewHandler).Methods("GET", "POST")
    50  	r.HandleFunc("/upload-image", handlers.UploadImageHandler).Methods("GET", "POST")
    51  	r.HandleFunc("/upload-video", handlers.UploadVideoHandler).Methods("GET", "POST")
    52  	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
    53  	http.Handle("/", middleware.PanicRecoveryHandler(ghandlers.LoggingHandler(os.Stdout, r)))
    54  	http.ListenAndServe(WEBSERVERPORT, nil)
    55  
    56  }