lib

package
v0.0.0-...-ef346fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorMissingRequiredFields = errors.New("missing required fields")
	ErrorMissingRequiredParams = errors.New("missing required params")
	ErrorUnauthorized          = errors.New("missing required credentials")
	ErrorUnprocessableEntity   = errors.New("UnprocessableEntity")
)

List of the error messages.

Functions

func CheckPassword

func CheckPassword(hashedPwd string, plainPwd string) bool

func GetClaimsFromRequest

func GetClaimsFromRequest(ctx context.Context) jwt.MapClaims

func GetUserIDFromRequest

func GetUserIDFromRequest(r *http.Request) int

func GetUserId

func GetUserId(ctx context.Context) int

func HashPassword

func HashPassword(pwd string) (string, error)

func NewLogger

func NewLogger() *logrus.Logger

func ReceiveJson

func ReceiveJson(r *http.Request, v render.Binder) error

ReceiveJson will extract the required struct that implements the binder interface returns a error if failed

func SendError

func SendError(w http.ResponseWriter, r *http.Request, httpStatusCode int, err error)

SendError sends the http code with given error message

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.

func ToJSON

func ToJSON(v interface{}) string

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

type OmitField

type OmitField *struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL