Example #1
0
func Run() {

	t = tango.New()

	t.Use(tango.Static(tango.StaticOptions{
		RootPath: utils.Abs(settings.Static.VirtualRoot),
	}))
	t.Use(binding.Bind())
	t.Use(new(time.TimeHandler))
	t.Use(tango.ClassicHandlers...)
	t.Use(renders.New(renders.Options{
		Reload:      true,
		Directory:   utils.Abs(settings.Template.Home),
		Charset:     settings.Template.Charset,
		DelimsLeft:  settings.Template.DelimesLeft,
		DelimsRight: settings.Template.DelimesRight,
		Funcs:       utils.DefaultFuncs(),
	}))
	t.Use(events.Events())
	t.Group("/pair", func(g *tango.Group) {
		g.Get("/all", new(pairs.GetAllRouter))
		g.Post("/new", new(pairs.NewPairRouter))
	})
	t.Get("/", new(page.HomeRouter))

	t.Run(settings.Server.Port)
}
Example #2
0
File: we.go Project: 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
}