~emersion/drmdb

23a5b90173a3675374d402b49b107a0d2a1e277a — Simon Ser 2 years ago 000801d
Move template data structures into handlers
1 files changed, 23 insertions(+), 27 deletions(-)

M server.go
M server.go => server.go +23 -27
@@ 33,30 33,6 @@ func badRequest(c echo.Context, msg string, err error) error {
	return c.String(http.StatusBadRequest, "Error: "+msg+"\n")
}

type indexData struct {
	Host string
}

type propertyData struct {
	Type       drm.PropertyType
	ObjectType drm.ObjectType
	Drivers    map[string]bool
}

type deviceData struct {
	Key     string
	BusID   string
	BusType drm.BusType
	Vendor  string
	Name    string
	Driver  string
}

type altDeviceData struct {
	Key    string
	Driver *drmtree.Driver
}

func walkProps(props drmtree.PropertyMap, obj drm.AnyID, f func(drm.AnyID, string, *drmtree.Property) error) error {
	for name, prop := range props {
		if err := f(obj, name, &prop); err != nil {


@@ 206,9 182,9 @@ func New() *echo.Echo {
	}

	e.GET("/", func(c echo.Context) error {
		return c.Render(http.StatusOK, "index.html", &indexData{
			Host: c.Request().Host,
		})
		return c.Render(http.StatusOK, "index.html", struct{
			Host string
		}{c.Request().Host})
	})

	e.POST("/submit", func(c echo.Context) error {


@@ 260,6 236,15 @@ func New() *echo.Echo {
	})

	e.GET("/devices", func(c echo.Context) error {
		type deviceData struct {
			Key     string
			BusID   string
			BusType drm.BusType
			Vendor  string
			Name    string
			Driver  string
		}

		var devices []deviceData
		err := walkLatest(walkLatestDevice, func(k string, n *drmtree.Node) error {
			data := deviceData{


@@ 292,6 277,11 @@ func New() *echo.Echo {
	})

	e.GET("/devices/:key", func(c echo.Context) error {
		type altDeviceData struct {
			Key    string
			Driver *drmtree.Driver
		}

		key := c.Param("key")
		raw := false
		if strings.HasSuffix(key, ".json") {


@@ 382,6 372,12 @@ func New() *echo.Echo {
	})

	e.GET("/properties", func(c echo.Context) error {
		type propertyData struct {
			Type       drm.PropertyType
			ObjectType drm.ObjectType
			Drivers    map[string]bool
		}

		drivers := make(map[string]struct{})
		props := make(map[string]propertyData)
		err := walk(func(k string, n *drmtree.Node) error {