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
type LoginResponse struct {
Success bool `json:"success"`
ErrorResponse
Token string `json:"token"`
Type string `json:"type"`
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 {
Success bool `json:"success"`
Message string `json:"message"`
}
type HelloWhoResponse struct {
Success bool `json:"success"`
BaseResponse
Error string `json:"error"`
Message string `json:"message"`
}

View File

@ -11,16 +11,20 @@ import (
func (h *Handler) DemoHello(c echo.Context) error {
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
BaseResponse: domain.BaseResponse{
Success: true,
Message: "Hello world!",
},
})
}
func (h *Handler) HelloWho(c echo.Context) error {
name := c.Param("who")
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
BaseResponse: domain.BaseResponse{
Success: true,
Message: fmt.Sprintf("Hello, %s", name),
},
})
}
@ -28,15 +32,14 @@ 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 h.InternalServerErrorResponse(c, err.Error())
}
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
BaseResponse: domain.BaseResponse{
Success: true,
Message: fmt.Sprintf("Hello, %s", request.Name),
},
})
}