Documentation ¶
Index ¶
- Variables
- func CheckAPI(next http.Handler) http.Handler
- func ErrDuplicateField(err error) render.Renderer
- func ErrInvalidRequest(err error) render.Renderer
- func ErrUnauthorized(err error) render.Renderer
- func ErrUnsupportedAPIVersion(err error) render.Renderer
- func FromContext(ctx context.Context) (string, bool)
- func Verifier(cfg *config.Config) func(next http.Handler) http.Handler
- type ErrResponse
- type Resource
Constants ¶
This section is empty.
Variables ¶
var ( ErrInternalServerError = &ErrResponse{ HTTPStatusCode: http.StatusInternalServerError, StatusText: http.StatusText(http.StatusInternalServerError), } ErrForbidden = &ErrResponse{ HTTPStatusCode: http.StatusForbidden, StatusText: http.StatusText(http.StatusForbidden), } )
The list of default error types without specific error message.
var ErrAPIUnsupported = errors.New("unsupported api version")
ErrAPIUnsupported an unsupported api version.
var ErrEmailTaken = errors.New("that email is taken")
ErrEmailTaken an already registered email.
var ErrInvalidEmailOrPassword = errors.New("invalid email or password")
ErrInvalidEmailOrPassword a wrong email or password field.
var ErrInvalidVerificationToken = errors.New("invalid or expired verification token")
ErrInvalidVerificationToken an expired or invalid verification token.
var ErrLoginToken = errors.New("invalid or expired login token")
ErrLoginToken an invalid or expired .
var ErrMissingAPIVersion = errors.New("missing api version header")
ErrMissingAPIVersion a missing api version header with the version text.
var ErrMissingToken = errors.New("missing authorization header")
ErrMissingToken a missing authorization header with the Bearer token.
var ErrNoSuchAccount = errors.New("no such account")
ErrNoSuchAccount a non-existent user account.
var ErrUnknownLogin = errors.New("email not registered")
ErrUnknownLogin an unregistered email field.
Functions ¶
func ErrDuplicateField ¶
ErrDuplicateField returns status 409 Status Conflict including error message.
func ErrInvalidRequest ¶
ErrInvalidRequest returns status 422 Unprocessable Entity including error message.
func ErrUnauthorized ¶
ErrUnauthorized renders status 401 Unauthorized with custom error message.
func ErrUnsupportedAPIVersion ¶
ErrUnsupportedAPIVersion returns status 400 Bad Request including error message.
func FromContext ¶
FromContext extracts user id from a Context
Types ¶
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message AppCode int64 `json:"code,omitempty"` // application-specific error code ErrorText string `json:"error,omitempty"` // application-level error message, for debugging }
ErrResponse renderer type for handling all sorts of errors.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(_ http.ResponseWriter, r *http.Request) error
Render sets the application-specific error code in AppCode.
type Resource ¶
Resource defines dependencies for auth handlers.
func NewResource ¶
NewResource returns a configured authentication resource.
func (Resource) HandleLogin ¶
func (rs Resource) HandleLogin(w http.ResponseWriter, r *http.Request)
HandleLogin login handler for handling login requests
func (Resource) HandleSignup ¶
func (rs Resource) HandleSignup(w http.ResponseWriter, r *http.Request)
HandleSignup signup handler func for handling requests for new accounts.
func (Resource) HandleVerify ¶
func (rs Resource) HandleVerify(w http.ResponseWriter, r *http.Request)
HandleVerify verify the verification code sent with the signup email