Пример #1
0
func startTango() {
	llog.SetOutput(new(mockResponseWriter))
	llog.SetOutputLevel(llog.Lnone)

	mux := tango.NewWithLog(llog.Std)
	mux.Get("/hello", tangoHandler)
	http.ListenAndServe(":"+strconv.Itoa(port), mux)
}
Пример #2
0
func init() {
	Server = tango.NewWithLog(log.Get().ToTangoLogger(), []tango.Handler{
		tango.Recovery(true),
		tango.Return(),
		tango.Param(),
		tango.Contexts(),
	}...)
}
Пример #3
0
// new http server with address
func NewServer(address string) *Server {
	s := &Server{
		address: address,
	}
	// use custom tango, not classic
	s.Tango = tango.NewWithLog(log.Get().ToTangoLogger(), []tango.Handler{
		tango.Logging(),
		tango.Recovery(true),
		tango.Return(),
		tango.Param(),
		tango.Contexts(),
	}...)
	return s
}
Пример #4
0
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
}