Documentation ¶
Index ¶
- Variables
- func MakeDeleteEndpoint(s Service) endpoint.Endpoint
- func MakeGetByIDEndpoint(s Service) endpoint.Endpoint
- func MakeGetProfileEndpoint(s Service) endpoint.Endpoint
- func MakeHTTPHandler(e Endpoints, log logger) http.Handler
- func MakeUpdateEmailEndpoint(s Service) endpoint.Endpoint
- func MakeUpdatePasswordEndpoint(s Service) endpoint.Endpoint
- func NewError(err error) *httpencoder.ErrorResponse
- type Endpoints
- type Service
- type UpdateEmailRequest
- type UpdatePasswordRequest
- type User
- type UserResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserNotFound = errors.New("user_not_found") ErrInvalidPassword = errors.New("invalid_password") ErrInvalidRequest = errors.New("invalid_request") ErrInvalidParameter = errors.New("invalid_parameter") ErrForbidden = errors.New("forbidden") )
Predefined errors.
var ErrorCodes = map[error]int{ ErrUserNotFound: http.StatusNotFound, ErrInvalidPassword: http.StatusPreconditionFailed, ErrInvalidRequest: http.StatusBadRequest, ErrInvalidParameter: http.StatusBadRequest, ErrForbidden: http.StatusForbidden, }
Error codes map
var ErrorMessages = map[error]string{ ErrUserNotFound: "User not found", ErrInvalidPassword: "Invalid current password", ErrInvalidRequest: "Invalid request", ErrInvalidParameter: "Invalid parameter", ErrForbidden: "Forbidden action", }
Error messages
Functions ¶
func MakeDeleteEndpoint ¶
MakeDeleteEndpoint returns an endpoint via the passed service.
func MakeGetByIDEndpoint ¶
MakeGetByIDEndpoint returns an endpoint via the passed service.
func MakeGetProfileEndpoint ¶
MakeGetProfileEndpoint returns an endpoint via the passed service.
func MakeHTTPHandler ¶
MakeHTTPHandler ...
func MakeUpdateEmailEndpoint ¶
MakeUpdateEmailEndpoint returns an endpoint via the passed service.
func MakeUpdatePasswordEndpoint ¶
MakeUpdatePasswordEndpoint returns an endpoint via the passed service.
Types ¶
type Endpoints ¶
type Endpoints struct { GetByID endpoint.Endpoint GetProfile endpoint.Endpoint UpdateEmail endpoint.Endpoint UpdatePassword endpoint.Endpoint Delete endpoint.Endpoint }
Endpoints collects all of the endpoints that compose a user service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter.
func MakeEndpoints ¶
func MakeEndpoints(s Service, m ...endpoint.Middleware) Endpoints
MakeEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the provided service. Primarily useful in a server.
type Service ¶
type Service interface { // GetByID returns the user with the specified the user ID. GetByID(ctx context.Context, id string) (*User, error) // UpdateEmail updates the email address of the user with the specified ID. UpdateEmail(ctx context.Context, id, email string) (*User, error) // UpdatePassword updates the password of the user with the specified ID. UpdatePassword(ctx context.Context, id, oldPassword, newPassword string) error // Delete deletes the user with the specified ID. Delete(ctx context.Context, id string) error }
func NewService ¶
NewService creates a new user service. It is the concrete implementation of the Service interface.
type UpdateEmailRequest ¶
type UpdateEmailRequest struct {
Email string `` /* 137-byte string literal not displayed */
}
UpdateEmailRequest is the request type for the UpdateEmail endpoint.
type UpdatePasswordRequest ¶
type UpdatePasswordRequest struct { Password string `json:"password" validate:"required" filter:"trim" label:"Current password"` NewPassword string `json:"new_password" validate:"required|minLen:8|maxLen:50" filter:"trim" label:"New password"` }
UpdatePasswordRequest is the request type for the UpdatePassword endpoint.
type User ¶
type User struct { ID string `json:"id"` Email string `json:"email"` Verified bool `json:"verified"` CreatedAt string `json:"created_at"` }
func NewUser ¶
func NewUser(u repository.User) *User
NewUser casts a repository.User to a user.User.
type UserResponse ¶
type UserResponse struct {
User *User `json:"user"`
}