Documentation ¶
Index ¶
- type BaseAPI
- func (b *BaseAPI) DecodeJSONReq(v interface{}) error
- func (b *BaseAPI) DecodeJSONReqAndValidate(v interface{}) (bool, error)
- func (b *BaseAPI) GetIDFromURL() (int64, error)
- func (b *BaseAPI) GetInt64FromPath(key string) (int64, error)
- func (b *BaseAPI) GetPaginationParams() (page, pageSize int64, err error)
- func (b *BaseAPI) GetStringFromPath(key string) string
- func (b *BaseAPI) ParseAndHandleError(text string, err error)
- func (b *BaseAPI) Redirect(statusCode int, resouceID string)
- func (b *BaseAPI) Render() error
- func (b *BaseAPI) RenderError(code int, text string)
- func (b *BaseAPI) RenderFormattedError(errorCode int, errorMsg string)
- func (b *BaseAPI) SendBadRequestError(err error)
- func (b *BaseAPI) SendConflictError(err error)
- func (b *BaseAPI) SendForbiddenError(err error)
- func (b *BaseAPI) SendInternalServerError(err error)
- func (b *BaseAPI) SendNotFoundError(err error)
- func (b *BaseAPI) SendPreconditionFailedError(err error)
- func (b *BaseAPI) SendStatusServiceUnavailableError(err error)
- func (b *BaseAPI) SendUnAuthorizedError(err error)
- func (b *BaseAPI) SetPaginationHeader(total, page, pageSize int64)
- func (b *BaseAPI) Validate(v interface{}) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseAPI ¶
type BaseAPI struct {
beego.Controller
}
BaseAPI wraps common methods for controllers to host API
func (*BaseAPI) DecodeJSONReq ¶
DecodeJSONReq decodes a json request
func (*BaseAPI) DecodeJSONReqAndValidate ¶
DecodeJSONReqAndValidate does both decoding and validation
func (*BaseAPI) GetIDFromURL ¶
GetIDFromURL checks the ID in request URL
func (*BaseAPI) GetInt64FromPath ¶
GetInt64FromPath gets the param from path and returns it as int64
func (*BaseAPI) GetPaginationParams ¶
GetPaginationParams ...
func (*BaseAPI) GetStringFromPath ¶
GetStringFromPath gets the param from path and returns it as string
func (*BaseAPI) ParseAndHandleError ¶
ParseAndHandleError : if the err is an instance of utils/error.Error, return the status code and the detail message contained in err, otherwise return 500
func (*BaseAPI) RenderError ¶
RenderError provides shortcut to render http error
func (*BaseAPI) RenderFormattedError ¶
RenderFormattedError renders errors with well formatted style
func (*BaseAPI) SendBadRequestError ¶
SendBadRequestError sends bad request error to the client.
func (*BaseAPI) SendConflictError ¶
SendConflictError sends conflict error to the client.
func (*BaseAPI) SendForbiddenError ¶
SendForbiddenError sends forbidden error to the client.
func (*BaseAPI) SendInternalServerError ¶
SendInternalServerError sends internal server error to the client. Note the detail info of err will not include in the response body. When you send an internal server error to the client, you expect user to check the log to find out the root cause.
func (*BaseAPI) SendNotFoundError ¶
SendNotFoundError sends not found error to the client.
func (*BaseAPI) SendPreconditionFailedError ¶
SendPreconditionFailedError sends conflict error to the client.
func (*BaseAPI) SendStatusServiceUnavailableError ¶
SendStatusServiceUnavailableError sends service unavailable error to the client.
func (*BaseAPI) SendUnAuthorizedError ¶
SendUnAuthorizedError sends unauthorized error to the client.
func (*BaseAPI) SetPaginationHeader ¶
SetPaginationHeader set"Link" and "X-Total-Count" header for pagination request