Exemplo n.º 1
0
func main() {
	port := os.Getenv("PORT")
	if port == "" {
		log.Fatal("$PORT must be set")
	}

	gin.SetMode(gin.ReleaseMode)

	app := gin.Default()
	app.Use(gzip.Gzip(gzip.DefaultCompression))

	app.GET("/", func(c *gin.Context) {
		c.String(http.StatusOK, "Go away.")
	})

	app.POST("/url", func(c *gin.Context) {
		url := c.PostForm("_url")

		log.Print(url)
		resp, err := http.Get(url)
		if err != nil {
			// handle error
		}
		defer resp.Body.Close()
		body, err := ioutil.ReadAll(resp.Body)

		c.Data(http.StatusOK, "text/html; charset=windows-1251", body)
	})

	app.Run(":" + port)
}
Exemplo n.º 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")
}