Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • development
  • analytics
  • mock
  • ui
  • interactor
  • room
  • retrofit
  • travis
  • bugfix
  • mvp
  • 0.6
  • 0.5
  • 0.4
  • 0.3
  • 0.2
16 results

XKCD.keystore

Blame
  • 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
    		}
    	}
    }