Refresh Token Support and package refactor based on best practice docs #18

Merged
jtom38 merged 15 commits from features/restructure-go-recommendations into main 2024-04-21 10:30:52 -07:00
2 changed files with 29 additions and 15 deletions
Showing only changes of commit e218da5e7d - Show all commits

View File

@ -1,19 +1,30 @@
package domain package domain
type LoginResponse struct { type LoginResponse struct {
Success bool `json:"success"` ErrorResponse
Token string `json:"token"` Token string `json:"token"`
Type string `json:"type"` Type string `json:"type"`
RefreshToken string `json:"refreshToken"` RefreshToken string `json:"refreshToken"`
} }
// This /
// /auth/refreshToken
type TokenRefreshResponse struct {
ErrorResponse
}
type BaseResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
}
type ErrorResponse struct { type ErrorResponse struct {
Success bool `json:"success"` Success bool `json:"success"`
Message string `json:"message"` Message string `json:"message"`
} }
type HelloWhoResponse struct { type HelloWhoResponse struct {
Success bool `json:"success"` BaseResponse
Error string `json:"error"` Error string `json:"error"`
Message string `json:"message"`
} }

View File

@ -11,16 +11,20 @@ import (
func (h *Handler) DemoHello(c echo.Context) error { func (h *Handler) DemoHello(c echo.Context) error {
return c.JSON(http.StatusOK, domain.HelloWhoResponse{ return c.JSON(http.StatusOK, domain.HelloWhoResponse{
BaseResponse: domain.BaseResponse{
Success: true, Success: true,
Message: "Hello world!", Message: "Hello world!",
},
}) })
} }
func (h *Handler) HelloWho(c echo.Context) error { func (h *Handler) HelloWho(c echo.Context) error {
name := c.Param("who") name := c.Param("who")
return c.JSON(http.StatusOK, domain.HelloWhoResponse{ return c.JSON(http.StatusOK, domain.HelloWhoResponse{
BaseResponse: domain.BaseResponse{
Success: true, Success: true,
Message: fmt.Sprintf("Hello, %s", name), Message: fmt.Sprintf("Hello, %s", name),
},
}) })
} }
@ -28,15 +32,14 @@ func (h *Handler) HelloBody(c echo.Context) error {
request := domain.HelloBodyRequest{} request := domain.HelloBodyRequest{}
err := (&echo.DefaultBinder{}).BindBody(c, &request) err := (&echo.DefaultBinder{}).BindBody(c, &request)
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, domain.HelloWhoResponse{ return h.InternalServerErrorResponse(c, err.Error())
Success: false,
Error: err.Error(),
})
} }
return c.JSON(http.StatusOK, domain.HelloWhoResponse{ return c.JSON(http.StatusOK, domain.HelloWhoResponse{
BaseResponse: domain.BaseResponse{
Success: true, Success: true,
Message: fmt.Sprintf("Hello, %s", request.Name), Message: fmt.Sprintf("Hello, %s", request.Name),
},
}) })
} }