/
server.go
77 lines (59 loc) · 2.46 KB
/
server.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"net/http"
"github.com/prashanthrv/sangeeblog/Godeps/_workspace/src/github.com/golang/glog"
//"github.com/prashanthrv/sangeeblog/Godeps/_workspace/src/github.com/gorilla/context"
"github.com/prashanthrv/sangeeblog/controllers"
"github.com/prashanthrv/sangeeblog/system"
"github.com/prashanthrv/sangeeblog/Godeps/_workspace/src/github.com/zenazn/goji"
"github.com/prashanthrv/sangeeblog/Godeps/_workspace/src/github.com/zenazn/goji/graceful"
"github.com/prashanthrv/sangeeblog/Godeps/_workspace/src/github.com/zenazn/goji/web"
//"golang.org/x/net/http2"
)
func main() {
// filename := flag.String("config", "config.toml", "Path to configuration file")
//
// flag.Parse()
filename := "config.toml"
defer glog.Flush()
var application = &system.Application{}
application.Init(&filename)
application.LoadTemplates()
// Setup static files
static := web.New()
publicPath := application.Config.Get("general.public_path").(string)
static.Get("/assets/*", http.StripPrefix("/assets/", http.FileServer(http.Dir(publicPath))))
http.Handle("/assets/", static)
// Apply middleware
//goji.Use(application.ApplyTemplates)
//goji.Use(application.ApplySessions)
//goji.Use(application.ApplyDbMap)
goji.Use(application.ApplyGormDB)
//goji.Use(application.ApplyAuth)
//goji.Use(application.ApplyIsXhr)
//goji.Use(application.ApplyCsrfProtection)
//goji.Use(context.ClearHandler)
controller := &controllers.MainController{}
// Couple of files - in the real world you would use nginx to serve them.
goji.Get("/robots.txt", http.FileServer(http.Dir(publicPath)))
goji.Get("/favicon.ico", http.FileServer(http.Dir(publicPath+"/images")))
// Home page
goji.Get("/", application.Route(controller, "Blog"))
// Sign In routes
goji.Get("/signin", application.Route(controller, "SignIn"))
goji.Post("/signin", application.Route(controller, "SignInPost"))
// Sign Up routes
goji.Get("/signup", application.Route(controller, "SignUp"))
goji.Post("/signup", application.Route(controller, "SignUpPost"))
// KTHXBYE
goji.Get("/logout", application.Route(controller, "Logout"))
goji.Get("/blog", application.Route(controller, "Blog"))
goji.Get("/post/:postid", application.Route(controller, "Post"))
goji.Get("/category/:categoryid", application.Route(controller, "Categories"))
goji.Get("/page/:pageid", application.Route(controller, "Pages"))
graceful.PostHook(func() {
application.Close()
})
goji.Serve()
//http2.ConfigureServer(http, &http2.Server{})
}