-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.go
43 lines (37 loc) · 1015 Bytes
/
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
package main
import (
"os"
"net/http"
"strings"
"io/ioutil"
"helloworldquiz/controllers"
"github.com/krasnoukhov/beego"
"github.com/krasnoukhov/train"
)
func main() {
// Config
if os.Getenv("GO_ENV") == "prod" {
beego.RunMode = "prod"
}
// Assets
beego.SetStaticPath("/public", "public")
beego.AddFuncMap("javascript_tag", train.JavascriptTag)
beego.AddFuncMap("stylesheet_tag", train.StylesheetTag)
beego.AddFuncMap("app", func () (out string) {
source, _ := ioutil.ReadFile("views/app.hbs")
return string(source[:])
})
// Routes
beego.Router("/", &controllers.MainController{})
beego.RESTRouter("/game", &controllers.GameController{})
beego.Router("/stats", &controllers.StatsController{})
train.SetFileServer()
beego.Errorhandler("404", func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/assets") {
train.ServeRequest(w, r)
} else {
http.Redirect(w, r, "/", 302)
}
})
beego.Run()
}