package httpserver import ( "database/sql" "errors" echo "github.com/labstack/echo/v4" "git.janky.solutions/finn/lockserver/db" "git.janky.solutions/finn/lockserver/frontend" ) type indexTemplateData struct { baseTemplateData ActiveCodes []db.IssuedCode Locks []db.Lock } func indexHandler(c echo.Context) error { queries, dbc, err := db.Get() if err != nil { return err } defer dbc.Close() ctx := c.Request().Context() activeCodes, err := queries.GetActiveCodes(ctx) if err != nil && !errors.Is(err, sql.ErrNoRows) { return err } locks, err := queries.GetLocks(ctx) if err != nil && !errors.Is(err, sql.ErrNoRows) { return err } return frontend.Templates.ExecuteTemplate(c.Response(), "index.html", indexTemplateData{ baseTemplateData: getBaseTemplateData(c.Request().Header), ActiveCodes: activeCodes, Locks: locks, }) }