Beispiel #1
0
func main() {
	r := gin.New()
	r.Use(gin.LoggerWithWriter(log.Writer()))
	r.Use(gin.RecoveryWithWriter(log.Writer()))

	r.SetHTMLTemplate(tmpl.MustLoad("templates/*"))

	r.NoRoute(ctl.Render404)
	r.Static("/s", "public")
	r.GET("/", page.Home)

	r.POST("/login", users.Login)
	r.GET("/register", users.RegistrationForm)
	r.POST("/register", users.Register)
	r.POST("/logout", users.Logout)

	r.POST("/list-create", todos.CreateList)
	r.GET("/list/:id", todos.ShowList)
	r.POST("/list/:id/update", todos.UpdateList)
	r.POST("/list/:id/destroy", todos.DestroyList)
	r.POST("/list/:id/add", todos.CreateTask)
	r.POST("/task/:id/update", todos.UpdateTask)
	r.POST("/task/:id/destroy", todos.DestroyTask)

	r.GET("/admin", admin.Index)
	r.GET("/admin/u/:name", admin.User)

	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	r.Run(":" + port)
}
Beispiel #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")
}
Beispiel #3
0
// NewServer запускает тестовый сервер на случайном порте, который направляет
// входящие подключения на функцию fn.
func NewServer(fn gin.HandlerFunc) *Server {
	gin.SetMode(gin.TestMode)

	r := gin.New()
	r.SetHTMLTemplate(tmpl.MustLoad("../../templates/*"))
	r.GET(testURL, fn)
	r.POST(testURL, fn)

	htserver := httptest.NewServer(r)
	serverURL, err := url.Parse(htserver.URL + testURL)
	if err != nil {
		panic(err)
	}
	return &Server{URL: serverURL}
}
Beispiel #4
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)
}