features/bootstrapping #1
@ -3,7 +3,6 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
|
||||||
@ -76,39 +75,6 @@ func NewServer(ctx context.Context, configs config.Configs, apiClient apiclient.
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// This custom Render replaces Echo's echo.Context.Render() with templ's templ.Component.Render().
|
|
||||||
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
|
||||||
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
|
||||||
ctx.Response().Writer.WriteHeader(statusCode)
|
|
||||||
return t.Render(ctx.Request().Context(), ctx.Response().Writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func (s *Handler) WriteError(c echo.Context, errMessage error, HttpStatusCode int) error {
|
|
||||||
return c.JSON(HttpStatusCode, domain.BaseResponse{
|
|
||||||
Message: errMessage.Error(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Handler) WriteMessage(c echo.Context, msg string, HttpStatusCode int) error {
|
|
||||||
return c.JSON(HttpStatusCode, domain.BaseResponse{
|
|
||||||
Message: msg,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Handler) InternalServerErrorResponse(c echo.Context, msg string) error {
|
|
||||||
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
|
||||||
Message: msg,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Handler) UnauthorizedResponse(c echo.Context, msg string) error {
|
|
||||||
return c.JSON(http.StatusUnauthorized, domain.BaseResponse{
|
|
||||||
Message: msg,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// If the token is not valid then an json error will be returned.
|
// If the token is not valid then an json error will be returned.
|
||||||
// If the token has the wrong scope, a json error will be returned.
|
// If the token has the wrong scope, a json error will be returned.
|
||||||
// If the token passes all the checks, it is valid and is returned back to the caller.
|
// If the token passes all the checks, it is valid and is returned back to the caller.
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
|
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
|
||||||
|
"github.com/a-h/templ"
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@ -60,3 +61,18 @@ func ValidateJwt(ctx echo.Context, sharedSecret, issuer string) (jwtToken, error
|
|||||||
|
|
||||||
return *claims, nil
|
return *claims, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
||||||
|
ctx.Response().Writer.WriteHeader(statusCode)
|
||||||
|
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||||
|
|
||||||
|
// take the request context and make it a var
|
||||||
|
request := ctx.Request().Context()
|
||||||
|
//Check to see if we the echo context has the cookie we are looking for, if so, create a new context based on what we had and add the value
|
||||||
|
//darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode)
|
||||||
|
//if err == nil {
|
||||||
|
// request = context.WithValue(request, domain.CookieSettingsDarkMode, darkMode.Value)
|
||||||
|
//}
|
||||||
|
|
||||||
|
return t.Render(request, ctx.Response().Writer)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user