51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.javil.eu/jacob1123/budgeteer"
|
|
|
|
"gopkg.in/gin-gonic/gin.v1"
|
|
)
|
|
|
|
// Handler handles incoming requests
|
|
type Handler struct {
|
|
UserService budgeteer.UserService
|
|
}
|
|
|
|
func (h *Handler) Serve() {
|
|
|
|
router := gin.Default()
|
|
|
|
router.LoadHTMLGlob("./templates/*")
|
|
router.Static("/static", "./static")
|
|
|
|
router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index", nil) })
|
|
router.GET("/login", login)
|
|
api := router.Group("/api/v1")
|
|
{
|
|
api.GET("/logout", logout)
|
|
api.GET("/login", func(c *gin.Context) {
|
|
c.Redirect(http.StatusPermanentRedirect, "/login")
|
|
})
|
|
api.POST("/login", loginPost)
|
|
|
|
// Unauthenticated routes
|
|
api.GET("/check", func(c *gin.Context) {
|
|
c.String(http.StatusOK, "Accessible")
|
|
})
|
|
api.GET("/hello", func(c *gin.Context) {
|
|
c.String(http.StatusOK, "Hello, World!")
|
|
})
|
|
|
|
// Restricted group
|
|
r := api.Group("/restricted")
|
|
{
|
|
//r.Use(middleware.JWT([]byte(secret)))
|
|
r.GET("", restricted)
|
|
}
|
|
}
|
|
|
|
router.Run(":1323")
|
|
}
|