package v1 import ( "fmt" "go-cook/api/domain" "net/http" "github.com/labstack/echo/v4" ) func (h *Handler) DemoHello(c echo.Context) error { return c.JSON(http.StatusOK, domain.HelloWhoResponse{ Success: true, Message: "Hello world!", }) } func (h *Handler) HelloWho(c echo.Context) error { name := c.Param("who") return c.JSON(http.StatusOK, domain.HelloWhoResponse{ Success: true, Message: fmt.Sprintf("Hello, %s", name), }) } func (h *Handler) HelloBody(c echo.Context) error { request := domain.HelloBodyRequest{} err := (&echo.DefaultBinder{}).BindBody(c, &request) if err != nil { return c.JSON(http.StatusBadRequest, domain.HelloWhoResponse{ Success: false, Error: err.Error(), }) } return c.JSON(http.StatusOK, domain.HelloWhoResponse{ Success: true, Message: fmt.Sprintf("Hello, %s", request.Name), }) } func (h *Handler) ProtectedRoute(c echo.Context) error { token, err := h.getJwtToken(c) if err != nil { h.ReturnUnauthorizedResponse(c, err.Error()) } err = token.IsValid(domain.ScopeRecipeRead) if err != nil { h.ReturnUnauthorizedResponse(c, ErrJwtScopeMissing) } return c.JSON(http.StatusOK, token) }