-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.go
44 lines (36 loc) · 953 Bytes
/
static.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
package main
import (
"github.com/kataras/iris"
)
func staticContent() {
// public content
iris.Static("/public", "./public/", 1)
iris.Get("/login.html", func(ctx *iris.Context) {
ctx.ServeFile("./login.html", false)
})
iris.Get("/docs", func(ctx *iris.Context) {
ctx.ServeFile("./docs/index.html", false)
})
iris.Get("/docs/index.html", func(ctx *iris.Context) {
ctx.ServeFile("./docs/index.html", false)
})
protected := func(handler iris.HandlerFunc) iris.HandlerFunc {
return func(ctx *iris.Context) {
// TODO better approach to authorize
user := getCurrentUser(ctx)
if user == nil {
ctx.Redirect("/login.html")
return
}
handler(ctx)
}
}
index := protected(func(ctx *iris.Context) {
ctx.ServeFile("./index.html", false)
})
iris.Get("/", index)
iris.Get("/index.html", index)
iris.Get("/statistics.html", protected(func(ctx *iris.Context) {
ctx.ServeFile("./statistics.html", false)
}))
}