-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
63 lines (48 loc) · 1.37 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"net/http"
"github.com/gobbl/bouncer/controllers"
"github.com/gobbl/bouncer/models"
"github.com/gorilla/mux"
)
var port int
func init() {
const (
defaultPort = 8080
portUsage = "port number"
)
flag.IntVar(&port, "p", defaultPort, portUsage)
}
func setupServer() *mux.Router {
r := mux.NewRouter().StrictSlash(false)
r.HandleFunc("/", controllers.GetHomeHandler).Methods("GET")
r.HandleFunc("/status", controllers.GetStatusHandler).Methods("GET")
/*
signup := r.Path("/signup").Subrouter()
signup.Methods("POST").HandlerFunc(signHandler)
// Posts collection
signup := r.Path("/signup").Subrouter()
signup.Methods("GET").HandlerFunc(PostsIndexHandler)
signup.Methods("POST").HandlerFunc(PostsCreateHandler)
// Posts singular
login := r.PathPrefix("/login/{id}").Subrouter()
login.Methods("GET").Path("/edit").HandlerFunc(PostEditHandler).Schemes("http")
login.Methods("GET").HandlerFunc(PostShowHandler)
login.Methods("PUT", "POST").HandlerFunc(PostUpdateHandler)
login.Methods("DELETE").HandlerFunc(PostDeleteHandler)
*/
return r
}
func main() {
flag.Parse()
r := setupServer()
models.Start()
defer models.Close()
fmt.Printf("Starting server on port:%d", port)
http.ListenAndServe(fmt.Sprintf(":%d", port), r)
}
func signHandler(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintln(rw, "signHandler")
}