Exemple #1
0
func init() {
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		revel.SessionFilter,           // Restore and write the session cookie.
		revel.FlashFilter,             // Restore and write the flash cookie.
		revel.ValidationFilter,        // Restore kept validation errors and save new ones from cookie.
		revel.I18nFilter,              // Resolve the requested language
		HeaderFilter,                  // Add some security based headers
		revel.InterceptorFilter,       // Run interceptors around the action.
		revel.CompressFilter,          // Compress the result.
		revel.ActionInvoker,           // Invoke the action.
	}

	// register startup functions with OnAppStart

	// ( order dependent )
	// revel.OnAppStart(InitDB)
	mgowrap.SetupDatbase("localhost", "demo")
	revel.InterceptMethod(controllers.WXAccessToken.CheckAccessToken, revel.BEFORE)

	// revel.OnAppStart(FillCache)
}
Exemple #2
0
func main() {
	handlers.LongCon()
	// Init Gin and setup the router
	mgowrap.SetupDatbase("localhost", "userdb")

	router := gin.Default()
	// router.LoadHTMLGlob("template/*")

	{
		// router.POST("/menu", createMenu)
		// router.GET("/menu", listMenu)
		// router.GET("/menu/:id", getOneMenu)
		// router.PATCH("", ...)
		// router.DELETE(relativePath, ...)
		router.GET("/createMenu", handlers.CreateMenu)
		router.GET("/wechatcreateQrcode", handlers.CreateQrcode)
		router.GET("/getQrcode", handlers.GetQrcode)
		router.GET("/toQrcode", handlers.ToQrcode)
		router.GET("/pushMsg", handlers.PushMsg)
		router.GET("/broad", broad)
		router.Any("/wx_callback", wxCallbackHandler)

		// /wechat/
		// router.GET("/", index)
	}

	log.Printf("Listening and serving http on %s\n", ":8080")
	router.Run(":8080")
	// log.Println(http.ListenAndServe(":8080", nil))
}
Exemple #3
0
// Get mongo server address from consul service
func SetupDBFromConsul(database string) {
	dbAddr, err := goutils.GetConsulServiceAddress("mongo")
	if err != nil {
		panic(err)
	}

	mgowrap.SetupDatbase(dbAddr, database)
}
Exemple #4
0
// ==================================
// The main logic for this simple app
//
func main() {

	// Setup DB
	mgowrap.SetupDatbase("localhost", "userdb")

	// Init Gin and setup the router
	router := gin.Default()
	router.LoadHTMLGlob("templates/*")

	{
		router.GET("/", userIndex)
		router.GET("/new", userNew)
		router.GET("/user/:id", userShow)
		router.POST("/user", userCreate)
	}

	log.Printf("Listening and serving http on %s\n", ":8081")
	router.Run(":8081")
}