Exemple #1
0
func main() {
	env = NewEnv()
	defer env.db.session.Close()

	// Creates a gin router with default middlewares:
	// logger and recovery (crash-free) middlewares
	// router := gin.Default()
	// Recovery returns a middleware that recovers from any panics and writes
	// a 500 if there was one.
	if m := os.Getenv("GIN_MODE"); m == "debug" {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}

	router := gin.New()
	router.Use(gin.Recovery())
	router.Use(gin.Logger())
	router.LoadHTMLGlob("templates/*.tmpl.html")
	router.Static("/static", "static")
	router.Static("/js", "js")
	router.StaticFile("/favicon.ico", "./img/favicon.ico")

	router.GET("/", indexFunc)

	router.GET("/info", mdFunc)

	dict := router.Group("/dictionary")
	{
		dict.GET("/rand", dbFunc)
	}

	router.Run(":" + env.port)
}
Exemple #2
0
func StartGin() {
	gin.SetMode(gin.ReleaseMode)

	router := gin.New()
	router.Use(rateLimit, gin.Recovery())
	router.LoadHTMLGlob("resources/*.templ.html")
	router.Static("/static", "resources/static")
	router.GET("/", index)
	router.GET("/room/:roomid", roomGET)
	router.POST("/room-post/:roomid", roomPOST)
	router.GET("/stream/:roomid", streamRoom)

	router.Run(":80")
}
Exemple #3
0
// This function's name is a must. App Engine uses it to drive the requests properly.
func init() {
	// Starts a new Gin instance with no middle-ware
	r := gin.New()

	// Define your handlers
	r.GET("/", func(c *gin.Context) {
		c.String(200, "Hello World!")
	})
	r.GET("/ping", func(c *gin.Context) {
		c.String(200, "pong")
	})

	// Handle all requests using net/http
	http.Handle("/", r)
}