Separate router initialization into it's own function
This commit is contained in:
parent
8ddb7a0f89
commit
c4373c8773
1 changed files with 5 additions and 2 deletions
|
@ -121,7 +121,11 @@ func main() {
|
||||||
db = initDB()
|
db = initDB()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
/* set up web handlers */
|
setUpRouter()
|
||||||
|
panic(http.ListenAndServe(":"+PORT, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func setUpRouter() {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.HandleFunc("/", indexHandler)
|
r.HandleFunc("/", indexHandler)
|
||||||
r.HandleFunc("/book/{id:[0-9a-fA-F]+}", bookHandler)
|
r.HandleFunc("/book/{id:[0-9a-fA-F]+}", bookHandler)
|
||||||
|
@ -149,5 +153,4 @@ func main() {
|
||||||
h = http.FileServer(http.Dir(JS_PATH))
|
h = http.FileServer(http.Dir(JS_PATH))
|
||||||
r.Handle("/js/{js}", http.StripPrefix("/js/", h))
|
r.Handle("/js/{js}", http.StripPrefix("/js/", h))
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
panic(http.ListenAndServe(":"+PORT, nil))
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue