static-hoster/src/router/router.go

30 lines
570 B
Go
Raw Normal View History

2023-01-24 14:50:38 +00:00
package router
import (
"net/http"
"github.com/gin-gonic/gin"
"nikurasu.gay/static-hoster/api"
2023-01-25 21:14:27 +00:00
"nikurasu.gay/static-hoster/envloader"
2023-01-24 14:50:38 +00:00
"nikurasu.gay/static-hoster/middleware/auth"
)
2023-01-25 21:14:27 +00:00
func Create(env *envloader.Environment) *gin.Engine {
2023-01-24 14:50:38 +00:00
router := gin.Default()
2023-01-26 17:52:03 +00:00
apiRoutes := router.Group("/api", auth.AuthMiddleware(env))
2023-01-24 14:50:38 +00:00
{
2023-01-26 17:52:03 +00:00
apiRoutes.POST("/update", api.PostUpdate(env))
2023-01-24 14:50:38 +00:00
}
// Ping test
router.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong")
})
2023-01-26 17:52:03 +00:00
router.Static("/home", env.StaticDir)
// TODO: Load 404 error Page
2023-01-24 14:50:38 +00:00
return router
}