package handlers import ( "templ-test/client" "templ-test/models" "templ-test/services" "github.com/a-h/templ" "github.com/labstack/echo/v4" ) const ( CookieToken = "token" CookieRefreshToken = "refresh" CookieUser = "user" ) type Handlers struct { api client.ApiClient cfg services.EnvConfig } func NewHandlerClient(api client.ApiClient, cfg services.EnvConfig) *Handlers { h := Handlers{ api: api, cfg: cfg, } return &h } func (h *Handlers) Register(group echo.Group) { group.GET("/", h.HomeHandler) group.GET("/list", h.ListHandler) auth := group.Group("/auth") auth.GET("/login", h.AuthLogin) auth.POST("/login", h.AuthLoginPost) auth.GET("/cookie", h.AuthShowCookies) } func Render(ctx echo.Context, statusCode int, t templ.Component) error { ctx.Response().Writer.WriteHeader(statusCode) ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) return t.Render(ctx.Request().Context(), ctx.Response().Writer) } func GetCookieValues(ctx echo.Context) models.AllCookies { m := models.AllCookies{} token, err := ctx.Cookie(CookieToken) if err == nil { m.Token = token.Value } user, err := ctx.Cookie(CookieUser) if err == nil { m.Username = user.Value } refresh, err := ctx.Cookie(CookieRefreshToken) if err == nil { m.RefreshToken = refresh.Value } return m }