Select Git revision
router.go 1.17 KiB
package web
import (
"errors"
"git.sch.bme.hu/blintmester/keresett-a-feri/route"
"github.com/gin-gonic/gin"
"io/fs"
"net/http"
)
var Router = gin.Default()
type StationURI struct {
Name string `uri:"name" binding:"required"`
Id string `uri:"uuid" binding:"required"`
}
func init() {
staticfs, e := fs.Sub(static, "static")
if e != nil {
panic(e)
}
Router.Use(errorHandler)
//Router.SetHTMLTemplate(html)
Router.StaticFS("/", http.FS(staticfs))
//for _, station := range route.Middle {
// Router.StaticFS("/" + station.Id, http.FS(staticfs))
//}
Router.GET("/:name/:uuid", routeChooser)
}
func routeChooser(c *gin.Context) {
var stationUri StationURI
if err := c.ShouldBindUri(&stationUri); err != nil {
c.Error(err)
return
}
if stationUri.Name != "station" {
c.Error(errors.New("wrong path")) // TODO: better error msg
return
}
if stationUri.Id == "first" {
c.HTML(http.StatusOK, "static/index.html", nil)
} else if stationUri.Id == "last" {
} else {
found := false
for _, station := range route.Middle {
if stationUri.Id == station.Id {
found = true
break
}
}
if !found {
c.Error(errors.New("wrong uuid"))
return
}
}
}