Refresh Token Support and package refactor based on best practice docs #18
@ -1,19 +1,30 @@
|
||||
package domain
|
||||
|
||||
type LoginResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Token string `json:"token"`
|
||||
Type string `json:"type"`
|
||||
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"`
|
||||
}
|
||||
|
@ -11,16 +11,20 @@ import (
|
||||
|
||||
func (h *Handler) DemoHello(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, domain.HelloWhoResponse{
|
||||
Success: true,
|
||||
Message: "Hello world!",
|
||||
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{
|
||||
Success: true,
|
||||
Message: fmt.Sprintf("Hello, %s", name),
|
||||
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{
|
||||
Success: true,
|
||||
Message: fmt.Sprintf("Hello, %s", request.Name),
|
||||
BaseResponse: domain.BaseResponse{
|
||||
Success: true,
|
||||
Message: fmt.Sprintf("Hello, %s", request.Name),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user