-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (35 loc) · 1.08 KB
/
main.go
File metadata and controls
42 lines (35 loc) · 1.08 KB
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
package main
import (
"log"
"net/http"
"strconv"
"github.com/gorilla/mux"
)
func main() {
LoadConfig("config/masher_config.json")
InitSession()
InitDB()
InitTemplates()
router := mux.NewRouter()
// pages
router.HandleFunc("/", ViewAbout)
router.HandleFunc("/new", ViewNew)
router.HandleFunc("/patch/{id}", ViewPatch)
router.HandleFunc("/user/{user}", ViewUser)
router.HandleFunc("/continue", ViewContinue)
router.HandleFunc("/browse", ViewBrowse)
router.HandleFunc("/learn", ViewLearn)
router.HandleFunc("/learn/{page}", ViewLearn)
// api endpoints
router.HandleFunc("/api/signup", Signup).Methods("POST")
router.HandleFunc("/api/login", Login).Methods("POST")
router.HandleFunc("/api/post", PostPatch).Methods("POST")
router.HandleFunc("/api/update", UpdatePatch).Methods("POST")
// redirects
router.HandleFunc("/logout", Logout)
router.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", 302)
})
router.NotFoundHandler = http.HandlerFunc(ViewNotFound)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(MasherConfig.Port), router))
}