api

package
v0.0.0-...-0d9dc4b Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 58

Documentation

Index

Constants

View Source
const (

	// APIVersion is the current core api version
	APIVersion = "v2.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseAPI

type BaseAPI struct {
	web.Controller
}

BaseAPI wraps common methods for controllers to host API

func (*BaseAPI) Context

func (b *BaseAPI) Context() context.Context

Context returns the context.Context from http.Request

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

func (b *BaseAPI) ParamExistsInPath(key string) bool

ParamExistsInPath returns true when param exists in the path

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

func (b *BaseAPI) SendBadRequestError(err error)

SendBadRequestError sends bad request error to the client.

func (*BaseAPI) SendConflictError

func (b *BaseAPI) SendConflictError(err error)

SendConflictError sends conflict error to the client.

func (*BaseAPI) SendError

func (b *BaseAPI) SendError(err error)

SendError return the error defined in OCI spec: https://github.com/opencontainers/distribution-spec/blob/master/spec.md#errors

{
	"errors:" [{
			"code": <error identifier>,
			"message": <message describing condition>,
			// optional
			"detail": <unstructured>
		},
		...
	]
}

func (*BaseAPI) SendForbiddenError

func (b *BaseAPI) SendForbiddenError(err error)

SendForbiddenError sends forbidden error to the client.

func (*BaseAPI) SendInternalServerError

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

func (b *BaseAPI) SendNotFoundError(err error)

SendNotFoundError sends not found error to the client.

func (*BaseAPI) SendPreconditionFailedError

func (b *BaseAPI) SendPreconditionFailedError(err error)

SendPreconditionFailedError sends conflict error to the client.

func (*BaseAPI) SendStatusServiceUnavailableError

func (b *BaseAPI) SendStatusServiceUnavailableError(err error)

SendStatusServiceUnavailableError sends service unavailable error to the client.

func (*BaseAPI) SendUnAuthorizedError

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