lockserver/httpserver/index.go
Finn 099692c91b debug log all incoming http headers
trying to figure out how to get baseurl
2024-11-22 19:50:54 -08:00

42 lines
852 B
Go

package httpserver
import (
"database/sql"
"errors"
echo "github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
"git.janky.solutions/finn/lockserver/db"
"git.janky.solutions/finn/lockserver/frontend"
)
type baseTemplateData struct {
Username string
UserDisplayName string
}
type indexTemplateData struct {
baseTemplateData
Locks []db.Lock
}
func indexHandler(c echo.Context) error {
for k, v := range c.Request().Header {
logrus.WithFields(logrus.Fields{"header": k, "value": v}).Debug("request header")
}
queries, dbc, err := db.Get()
if err != nil {
return err
}
defer dbc.Close()
locks, err := queries.GetLocks(c.Request().Context())
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
return frontend.Templates.ExecuteTemplate(c.Response(), "index.html", indexTemplateData{Locks: locks})
}