api

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func (b *BaseAPI) DecodeJSONReq(v interface{}) error

DecodeJSONReq decodes a json request

func (*BaseAPI) DecodeJSONReqAndValidate

func (b *BaseAPI) DecodeJSONReqAndValidate(v interface{}) (bool, error)

DecodeJSONReqAndValidate does both decoding and validation

func (*BaseAPI) GetIDFromURL

func (b *BaseAPI) GetIDFromURL() (int64, error)

GetIDFromURL checks the ID in request URL

func (*BaseAPI) GetInt64FromPath

func (b *BaseAPI) GetInt64FromPath(key string) (int64, error)

GetInt64FromPath gets the param from path and returns it as int64

func (*BaseAPI) GetPaginationParams

func (b *BaseAPI) GetPaginationParams() (page, pageSize int64, err error)

GetPaginationParams ...

func (*BaseAPI) GetStringFromPath

func (b *BaseAPI) GetStringFromPath(key string) string

GetStringFromPath gets the param from path and returns it as string

func (*BaseAPI) ParseAndHandleError

func (b *BaseAPI) ParseAndHandleError(text string, err error)

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) Redirect

func (b *BaseAPI) Redirect(statusCode int, resouceID string)

Redirect does redirection to resource URI with http header status code.

func (*BaseAPI) Render

func (b *BaseAPI) Render() error

Render returns nil as it won't render template

func (*BaseAPI) RenderError

func (b *BaseAPI) RenderError(code int, text string)

RenderError provides shortcut to render http error

func (*BaseAPI) RenderFormattedError added in v1.8.0

func (b *BaseAPI) RenderFormattedError(errorCode int, errorMsg string)

RenderFormattedError renders errors with well formatted style

func (*BaseAPI) SendBadRequestError added in v1.8.0

func (b *BaseAPI) SendBadRequestError(err error)

SendBadRequestError sends bad request error to the client.

func (*BaseAPI) SendConflictError added in v1.8.0

func (b *BaseAPI) SendConflictError(err error)

SendConflictError sends conflict error to the client.

func (*BaseAPI) SendForbiddenError added in v1.8.0

func (b *BaseAPI) SendForbiddenError(err error)

SendForbiddenError sends forbidden error to the client.

func (*BaseAPI) SendInternalServerError added in v1.8.0

func (b *BaseAPI) SendInternalServerError(err error)

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

func (b *BaseAPI) SendNotFoundError(err error)

SendNotFoundError sends not found error to the client.

func (*BaseAPI) SendPreconditionFailedError added in v1.8.0

func (b *BaseAPI) SendPreconditionFailedError(err error)

SendPreconditionFailedError sends conflict error to the client.

func (*BaseAPI) SendStatusServiceUnavailableError added in v1.8.0

func (b *BaseAPI) SendStatusServiceUnavailableError(err error)

SendStatusServiceUnavailableError sends service unavailable error to the client.

func (*BaseAPI) SendUnAuthorizedError added in v1.8.0

func (b *BaseAPI) SendUnAuthorizedError(err error)

SendUnAuthorizedError sends unauthorized error to the client.

func (*BaseAPI) SetPaginationHeader

func (b *BaseAPI) SetPaginationHeader(total, page, pageSize int64)

SetPaginationHeader set"Link" and "X-Total-Count" header for pagination request

func (*BaseAPI) Validate

func (b *BaseAPI) Validate(v interface{}) (bool, error)

Validate validates v if it implements interface validation.ValidFormer

Jump to

Keyboard shortcuts

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