Documentation ¶
Index ¶
- Variables
- func CheckPassword(hashedPwd string, plainPwd string) bool
- func GetClaimsFromRequest(ctx context.Context) jwt.MapClaims
- func GetUserIDFromRequest(r *http.Request) int
- func GetUserId(ctx context.Context) int
- func HashPassword(pwd string) (string, error)
- func NewLogger() *logrus.Logger
- func ReceiveJson(r *http.Request, v render.Binder) error
- func SendError(w http.ResponseWriter, r *http.Request, httpStatusCode int, err error)
- func SendErrorBadRequest(w http.ResponseWriter, r *http.Request, err error)
- func SendErrorInternalServer(w http.ResponseWriter, r *http.Request, err error)
- func SendErrorUnauthorized(w http.ResponseWriter, r *http.Request)
- func SendErrorUnprocessableEntity(w http.ResponseWriter, r *http.Request, err error)
- func SendJson(w http.ResponseWriter, r *http.Request, v interface{})
- func SendStatus(w http.ResponseWriter, r *http.Request, httpStatusCode int)
- func ToJSON(v interface{}) string
- type ErrResponse
- type OmitField
Constants ¶
This section is empty.
Variables ¶
var ( ErrorMissingRequiredFields = errors.New("missing required fields") ErrorMissingRequiredParams = errors.New("missing required params") ErrorUnprocessableEntity = errors.New("UnprocessableEntity") )
List of the error messages.
Functions ¶
func CheckPassword ¶
func GetClaimsFromRequest ¶
func GetUserIDFromRequest ¶
func HashPassword ¶
func ReceiveJson ¶
ReceiveJson will extract the required struct that implements the binder interface returns a error if failed
func SendErrorBadRequest ¶
func SendErrorBadRequest(w http.ResponseWriter, r *http.Request, err error)
SendErrorBadRequest sends the bad request with given error
func SendErrorInternalServer ¶
func SendErrorInternalServer(w http.ResponseWriter, r *http.Request, err error)
SendErrorInternalServer sends the bad request with given error
func SendErrorUnauthorized ¶
func SendErrorUnauthorized(w http.ResponseWriter, r *http.Request)
SendErrorUnauthorized sends the bad request with given error
func SendErrorUnprocessableEntity ¶
func SendErrorUnprocessableEntity(w http.ResponseWriter, r *http.Request, err error)
SendErrorUnprocessableEntity sends the unprocessable entity error
func SendJson ¶
func SendJson(w http.ResponseWriter, r *http.Request, v interface{})
SendJson sends a given json struct as response
func SendStatus ¶
func SendStatus(w http.ResponseWriter, r *http.Request, httpStatusCode int)
SendStatus only sends back the status without any message.
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 AppMessage string `json:"error,omitempty"` // application-level error message, for debugging }
ErrResponse renderer type for handling all sorts of errors.
In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.
func NewErrorResponse ¶
func NewErrorResponse(httpStatusCode int, err error) *ErrResponse
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error