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) ParamExistsInPath(key string) bool
- 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) ParamExistsInPath ¶ added in v1.8.6
ParamExistsInPath returns true when param exists in the path
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 ¶ added in v1.8.0
RenderFormattedError renders errors with well formatted style
func (*BaseAPI) SendBadRequestError ¶ added in v1.8.0
SendBadRequestError sends bad request error to the client.
func (*BaseAPI) SendConflictError ¶ added in v1.8.0
SendConflictError sends conflict error to the client.
func (*BaseAPI) SendForbiddenError ¶ added in v1.8.0
SendForbiddenError sends forbidden error to the client.
func (*BaseAPI) SendInternalServerError ¶ added in v1.8.0
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 ¶ added in v1.8.0
SendNotFoundError sends not found error to the client.
func (*BaseAPI) SendPreconditionFailedError ¶ added in v1.8.0
SendPreconditionFailedError sends conflict error to the client.
func (*BaseAPI) SendStatusServiceUnavailableError ¶ added in v1.8.0
SendStatusServiceUnavailableError sends service unavailable error to the client.
func (*BaseAPI) SendUnAuthorizedError ¶ added in v1.8.0
SendUnAuthorizedError sends unauthorized error to the client.
func (*BaseAPI) SetPaginationHeader ¶
SetPaginationHeader set"Link" and "X-Total-Count" header for pagination request