Documentation
¶
Overview ¶
The package api is responsible for handling requests and validating user input
Index ¶
- Variables
- func ErrorHandler(e error, c echo.Context)
- func Login(c echo.Context, userRepository *database.UserRepository, auth *echojwt.Config) error
- func NewAuthConfig() (*echojwt.Config, error)
- func NewServer(db *sql.DB) (*echo.Echo, error)
- func PasswordReset(c echo.Context, userRepository *database.UserRepository, auth *echojwt.Config) error
- type Error
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknown represents an unknown error. ErrUnknown = &Error{http.StatusInternalServerError, "UNKNOWN", nil, nil} ErrServiceUnavailable = &Error{http.StatusInternalServerError, "SERVICE_UNAVAILABLE", nil, nil} // ErrMissingParameters indicates that the user did not provide identity, password or desired role. ErrMissingParameters = &Error{http.StatusBadRequest, "MISSING_PARAMETERS", nil, nil} // ErrMissingParameters indicates that the user does not have a password in the database. ErrMissingPassword = &Error{http.StatusNotFound, "MISSING_PASSWORD", nil, nil} // ErrWrongIdentity indicates that no account was found with the provided parameters. ErrWrongIdentity = &Error{http.StatusUnauthorized, "WRONG_IDENTITY", nil, nil} // ErrAlreadyLoggedIn indicates that the user is already logged in (JWT token was provided). ErrAlreadyLoggedIn = &Error{http.StatusBadRequest, "ALREADY_LOGGED_IN", nil, nil} // ErrTokenNotProvided indicates that the user did not provide a token for reset API. ErrTokenNotProvided = &Error{http.StatusUnauthorized, "TOKEN_NOT_PROVIDED", nil, nil} // #nosec G101 // ErrTokenInvalid indicates that the user provided an invalid or expired token. ErrTokenInvalid = &Error{http.StatusUnauthorized, "INVALID_TOKEN", nil, nil} // ErrInvalidRoute indicates that the user tried to access an invalid route. ErrInvalidRoute = &Error{http.StatusNotFound, "INVALID_ROUTE", nil, nil} )
var ErrNoSecret = errors.New("$JWT_SECRET must be set")
ErrNoSecret indicates that the JWT_SECRET environment variable is not set.
Functions ¶
func ErrorHandler ¶
Custom error handler conformant with shared API rules.
func NewAuthConfig ¶
NewAuthConfig creates a new echojwt config from JWT_SECRET.
func PasswordReset ¶
func PasswordReset(c echo.Context, userRepository *database.UserRepository, auth *echojwt.Config) error
Password reset route handler.
Types ¶
type Error ¶
type Error struct {
// HTTP status code.
StatusCode int `json:"-"`
// Error type.
ErrorType string `json:"error"`
// Error details.
Details any `json:"details,omitempty"`
// Internal wrapped error. Not visible to users.
Internal error `json:"-"`
}
Represents an error that occurred in the API layer. API errors can be translated into a JSON object following shared API rules.
func (*Error) WithDetails ¶
Attaches detailed user-visible information to an API error. This is intended to give the API consumer more information about where and how it occurred.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Custom validator that uses go-playground/validator.
func NewValidator ¶
func NewValidator() *Validator
NewValidator creates a new instance of service.Validator.