Example #1
0
func main() {
	port := os.Getenv("PORT")

	if port == "" {
		log.Fatal("$PORT must be set")
	}

	router := gin.New()
	router.Use(gin.Logger())
	router.LoadHTMLGlob("templates/*.tmpl.html")
	router.Static("/static", "static")

	sign := make(chan int)
	resp := make(chan int)

	router.GET("/", func(c *gin.Context) {
		go counter(sign, resp)
		c.HTML(http.StatusOK, "index.tmpl.html", nil)
	})

	router.GET("/show", func(c *gin.Context) {
		sign <- 1
		msg := <-resp
		c.String(200, strconv.Itoa(msg))
	})

	router.Run(":" + port)
}
Example #2
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.
	router := gin.New()
	router.Use(gin.Recovery())
	router.Use(gin.Logger())
	router.LoadHTMLGlob("templates/*.tmpl.html")
	router.Static("/static", "static")

	router.GET("/", indexFunc)

	router.GET("/mark", mdFunc)

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

	router.Run(":" + env.port)
}
Example #3
0
func main() {
	port := os.Getenv("PORT")

	if port == "" {
		log.Fatal("$PORT must be set")
	}

	router := gin.New()
	router.Use(gin.Logger())
	router.LoadHTMLGlob("templates/*.tmpl.html")
	router.Static("/static", "static")

	router.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.tmpl.html", nil)
	})

	router.Run(":" + port)
}
Example #4
0
func main() {
	port := os.Getenv("PORT")

	if port == "" {
		log.Fatal("$PORT must be set")
	}

	router := gin.New()
	router.Use(gin.Logger())

	router.POST("/wait", func(c *gin.Context) {
		second_str := c.DefaultQuery("seconds", "1")
		seconds, _ := strconv.Atoi(second_str)
		time.Sleep(time.Duration(seconds) * time.Second)

		c.JSON(http.StatusOK, gin.H{
			"status": "ok",
		})
	})

	router.Run(":" + port)
}