-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (45 loc) · 1.15 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
52
53
54
55
package main
import (
"github.com/kataras/iris"
"./config"
"github.com/minhlucvan/gotodo/controllers/home"
"github.com/minhlucvan/gotodo/middwares/i18n"
"github.com/minhlucvan/gotodo/middwares/logger"
"github.com/kataras/go-template/html"
"github.com/minhlucvan/gotodo/API/authapi"
"github.com/minhlucvan/gotodo/middwares/auth"
"github.com/minhlucvan/gotodo/exceptions"
)
func init(){
}
func setMiddlewares(){
iris.Use(logger.Handler)
iris.Use(i18n.Handler)
}
func setControllers(){
iris.Handle("GET", "/", home.Index())
}
func setAPI(){
iris.Handle("POST", "/login/", authapi.Login{})
admin := iris.Party("/admin")
admin.Use(auth.RequireRole("admin"))
admin.Get("/", func(ctx *iris.Context) {
ctx.WriteString("this is admin dashboard.")
})
}
func setConfig(){
iris.Config.IsDevelopment = config.DEV_MODE
iris.Static("/assets", config.ASSETSPATH, 1)
iris.UseTemplate(html.New(html.Config{Layout: config.TPL_LAYOUT})).Directory(config.TPL_LOCATION, config.TPL_FORMAT)
exceptions.CustomHTTPErrors()
}
func startServer(){
iris.Listen(config.SERVER_PORT)
}
func main(){
setConfig()
setMiddlewares()
setControllers()
setAPI()
startServer()
}