This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
routers.go
103 lines (95 loc) · 2.23 KB
/
routers.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"html/template"
"reflect"
"runtime"
"strings"
"time"
"github.com/go-xorm/dbweb/modules/public"
"github.com/go-xorm/dbweb/modules/templates"
"github.com/Unknwon/i18n"
"github.com/go-xorm/xorm"
"github.com/lunny/nodb"
"github.com/lunny/tango"
"github.com/tango-contrib/binding"
"github.com/tango-contrib/captcha"
"github.com/tango-contrib/debug"
"github.com/tango-contrib/flash"
"github.com/tango-contrib/renders"
"github.com/tango-contrib/session"
"github.com/go-xorm/dbweb/actions"
"github.com/go-xorm/dbweb/middlewares"
)
var (
sessionTimeout = time.Minute * 20
)
func isNil(a interface{}) bool {
if a == nil {
return true
}
aa := reflect.ValueOf(a)
return !aa.IsValid() || (aa.Type().Kind() == reflect.Ptr && aa.IsNil())
}
func InitTango(isDebug bool) *tango.Tango {
t := tango.New()
if isDebug {
t.Use(debug.Debug(debug.Options{
HideResponseBody: true,
IgnorePrefix: "/public",
}))
}
sess := session.New(session.Options{
MaxAge: sessionTimeout,
})
t.Use(
tango.Logging(),
tango.Recovery(false),
tango.Compresses([]string{}),
public.Static(),
tango.Return(),
tango.Param(),
tango.Contexts(),
binding.Bind(),
renders.New(renders.Options{
Reload: true,
Directory: "templates",
Funcs: template.FuncMap{
"isempty": func(s string) bool {
return len(s) == 0
},
"add": func(a, b int) int {
return a + b
},
"isNil": isNil,
"i18n": i18n.Tr,
"Range": func(size int) []struct{} {
return make([]struct{}, size)
},
"multi": func(a, b int) int {
return a * b
},
},
Vars: renders.T{
"GoVer": strings.Trim(runtime.Version(), "go"),
"TangoVer": tango.Version(),
"XormVer": xorm.Version,
"NodbVer": nodb.Version,
},
FileSystem: templates.FileSystem("templates"),
}),
captcha.New(),
sess,
middlewares.Auth("/login"),
flash.Flashes(sess),
)
t.Any("/", new(actions.Home))
t.Any("/login", new(actions.Login))
t.Any("/logout", new(actions.Logout))
t.Any("/addb", new(actions.Addb))
t.Any("/view", new(actions.View))
t.Any("/del", new(actions.Del))
t.Any("/delRecord", new(actions.DelRecord))
t.Any("/chgpass", new(actions.ChgPass))
t.Get("/test", new(actions.Test))
return t
}