-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (38 loc) · 1.2 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
51
package main
import (
"net/http"
"os"
"chrisbrindley.co.uk/controller"
"chrisbrindley.co.uk/model"
"chrisbrindley.co.uk/service"
"chrisbrindley.co.uk/view"
"github.com/gorilla/mux"
)
var (
conn = os.Getenv("DB_CONN")
)
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusNotFound)
view := view.NewView("main", "view/404.gohtml")
view.Render(w, nil)
}
func main() {
var s map[string]service.Factory
s = make(map[string]service.Factory)
s["Model/Db"] = model.NewDbConnection
s["Model/UserAuth"] = model.NewUserAuth
s["Model/UserService"] = model.NewUserService
s["Controller/UserController"] = controller.NewUser
srv := service.NewServices(s)
staticController := controller.NewStaticController()
userController, _ := srv.MustGet("Controller/UserController").(*controller.User)
r := mux.NewRouter()
r.Handle("/", staticController.Views["index"])
r.Handle("/contact", staticController.Views["contact"])
r.Handle("/faq", staticController.Views["faq"])
r.HandleFunc("/new", userController.NewHandler)
var h http.Handler = http.HandlerFunc(notFoundHandler)
r.NotFoundHandler = h
http.ListenAndServe(":8000", r)
}