Documentation ¶
Index ¶
- Constants
- func Decode(r *http.Request, val interface{}) error
- func ErrBadRequest(err error, message string) error
- func ErrForbidden(err error, message string) error
- func ErrInternal(err error, message string) error
- func ErrNewRequest(err error, status string, messageStatus string, httpStatus int) error
- func ErrNotFound(err error, message string) error
- func GetCode(ctx context.Context, tx *sql.Tx, prefix string, tableName string, ...) (string, error)
- func Response(w http.ResponseWriter, data interface{}, statusCode string, message string, ...) error
- func ResponseError(w http.ResponseWriter, err error) error
- func ResponseOK(w http.ResponseWriter, data interface{}, HTTPStatus int) error
- type App
- type Ctx
- type Error
- type ErrorResponse
- type Handler
- type Middleware
- type ResponseFormat
Constants ¶
const ( // StatusCodeOK is custome status code for ok StatusCodeOK string = "REBEL-200" // StatusCodeBadRequest is custome status code for bad request StatusCodeBadRequest string = "REBEL-400" // StatusCodeForbidden is custome status code for forbidden StatusCodeForbidden string = "REBEL-401" // StatusCodeInternalServerError is custome status for unkown error / internal server error StatusCodeInternalServerError string = "REBEL-500" // StatusCodeNotFound is custome status code for not found StatusCodeNotFound string = "REBEL-404" )
const ( // StatusMessageOK is custome status message for ok StatusMessageOK string = "OK" // StatusMessageBadRequest is custome status message for bad request StatusMessageBadRequest string = "Bad Request" // StatusMessageInternalError is custome status message for unknown error / internal server error StatusMessageInternalServerError string = "Internal Error" // StatusMessageNotFound is custome status message for data not found StatusMessageNotFound string = "Not Found" // StatusMessageForbidden is custome status message for forbidden StatusMessageForbidden string = "Forbidden" )
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads the body of an HTTP request looking for a JSON document. The body is decoded into the provided value.
func ErrBadRequest ¶
ErrBadRequest wraps a provided error with an HTTP status code and custome status code for bad request. This function should be used when handlers encounter expected errors.
func ErrForbidden ¶
ErrForbidden wraps a provided error with an HTTP status code and custome status code for forbidden. This function should be used when handlers encounter expected errors.
func ErrInternal ¶
ErrInternal wraps a provided error with an HTTP status code and custome status code for internal server error. This function should be used when handlers encounter expected errors.
func ErrNewRequest ¶
ErrNewRequest wraps a provided error with an HTTP status code and custome status code. This function should be used when handlers encounter expected errors.
func ErrNotFound ¶
ErrNotFound wraps a provided error with an HTTP status code and custome status code for not found. This function should be used when handlers encounter expected errors.
func GetCode ¶
func GetCode(ctx context.Context, tx *sql.Tx, prefix string, tableName string, companyID uint32) (string, error)
GetCode is function to generate code of transaction
func Response ¶
func Response(w http.ResponseWriter, data interface{}, statusCode string, message string, httpCode int) error
Response converts a Go value to JSON and sends it to the client.
func ResponseError ¶
func ResponseError(w http.ResponseWriter, err error) error
ResponseError sends an error reponse back to the client.
func ResponseOK ¶
func ResponseOK(w http.ResponseWriter, data interface{}, HTTPStatus int) error
ResponseOK converts a Go value to JSON and sends it to the client.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the entrypoint into our application and what controls the context of each request. Feel free to add any configuration data/logic on this type.
func NewApp ¶
func NewApp(log *log.Logger, mw ...Middleware) *App
NewApp is function to create new App
type Error ¶
Error is used to pass an error during the request through the application with web specific context.
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse is the form used for API responses from failures in the API.
type Handler ¶
type Handler func(http.ResponseWriter, *http.Request)
Handler type for force httprouter into standard http handler
type Middleware ¶
Middleware is a function designed to run some code before and/or after another Handler. It is designed to remove boilerplate or other concerns not direct to any given Handler.
type ResponseFormat ¶
type ResponseFormat struct { StatusCode string `json:"status_code"` Message string `json:"status_message"` Data interface{} `json:"data"` }
ResponseFormat is used to pass an response in standard format