-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (38 loc) · 1.49 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
44
45
46
47
48
49
50
package main
import (
"fmt"
"log"
"os"
"net/http"
"github.com/gorilla/mux"
"metagit.org/blizzlike/cmangos-website/modules/config"
"metagit.org/blizzlike/cmangos-website/modules/pages/landingpage"
"metagit.org/blizzlike/cmangos-website/modules/pages/login"
"metagit.org/blizzlike/cmangos-website/modules/pages/logout"
"metagit.org/blizzlike/cmangos-website/modules/pages/signup"
"metagit.org/blizzlike/cmangos-website/modules/pages/dashboard"
"metagit.org/blizzlike/cmangos-website/modules/pages/invite"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "USAGE: %s <config>\n", os.Args[0])
os.Exit(1)
}
cfg, err := config.Read(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to read file %v\n", err)
os.Exit(2)
}
router := mux.NewRouter()
router.HandleFunc("/login", login.RenderGet).Methods("GET")
router.HandleFunc("/login", login.RenderPost).Methods("POST")
router.HandleFunc("/logout", logout.Render).Methods("GET")
router.HandleFunc("/signup", signup.RenderGet).Methods("GET")
router.HandleFunc("/signup", signup.RenderPost).Methods("POST")
router.HandleFunc("/dashboard", dashboard.Render).Methods("GET")
router.HandleFunc("/invite", invite.RenderPost).Methods("POST")
router.HandleFunc("/", landingpage.Render).Methods("GET")
router.PathPrefix("/").Handler(
http.StripPrefix("/static/", http.FileServer(http.Dir(cfg.Static))))
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), router))
}