Ejemplo n.º 1
0
func InitTango(isDebug bool) *tango.Tango {
	t := tango.New()
	if isDebug {
		t.Use(debug.Debug(debug.Options{
			HideResponseBody: true,
			IgnorePrefix:     "/static",
		}))
	}
	t.Use(tango.ClassicHandlers...)
	sess := session.New(session.Options{
		MaxAge: sessionTimeout,
	})
	t.Use(
		binding.Bind(),
		tango.Static(tango.StaticOptions{
			RootPath: filepath.Join(*homeDir, "static"),
			Prefix:   "static",
		}),
		renders.New(renders.Options{
			Reload:    true,
			Directory: filepath.Join(*homeDir, "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,
			},
		}),
		middlewares.Auth("/login", sess),
		flash.Flashes(sess),
		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
}
Ejemplo n.º 2
0
Archivo: we.go Proyecto: trigrass2/wego
func initTango(isprod bool) *tango.Tango {
	middlewares.Init()

	tg := tango.NewWithLog(setting.Log)

	if false {
		//if !isprod {
		tg.Use(debug.Debug(debug.Options{
			IgnorePrefix:     "/static",
			HideResponseBody: true,
			HideRequestBody:  true,
		}))
	}

	tg.Use(tango.ClassicHandlers...)

	sess := session.New(session.Options{
		MaxAge: time.Duration(setting.SessionCookieLifeTime),
	})
	tg.Use(
		tango.Static(tango.StaticOptions{
			RootPath: "./static",
			Prefix:   "static",
		}),
		tango.Static(tango.StaticOptions{
			RootPath: "./static_source",
			Prefix:   "static_source",
		}),
		sess,
		middlewares.Renders,
		setting.Captcha,
	)
	tg.Get("/favicon.ico", func(ctx *tango.Context) {
		ctx.ServeFile("./static/favicon.ico")
	})
	if setting.EnableXSRF {
		tg.Use(xsrf.New(time.Duration(setting.SessionCookieLifeTime)))
	}
	tg.Use(flash.Flashes(sess), events.Events())
	return tg
}