apifunc

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResultCode_Unknown = iota
	ResultCode_EmptyParams
	ResultCode_ServiceNotFound = iota + 400
	ResultCode_FunctionNotFound
	ResultCode_InternalServerError = 500
	ResultCode_EmptyResponse       = 501
)

Variables

This section is empty.

Functions

func NewFunctionExecutor

func NewFunctionExecutor(registry *ApiServiceRegistry, opts ...interface{}) command.FileCommandExecuter

func ResponseJson

func ResponseJson(data interface{}) (*ApiResponse, *ApiError)

Types

type ApiError

type ApiError struct {
	Code  int
	Msg   string
	Cause error
}

func EmptyResponseErr

func EmptyResponseErr(srvId, funcId string) *ApiError

func Error

func Error(err error) *ApiError

func ErrorCoder

func ErrorCoder(coder command.ResultCoder) *ApiError

func ErrorMsg

func ErrorMsg(code int, msg string) *ApiError

func FunctionNotFoundErr

func FunctionNotFoundErr(funcId string) *ApiError

func ServiceNotFoundErr

func ServiceNotFoundErr(srvId string) *ApiError

func (ApiError) Error

func (a ApiError) Error() string

func (ApiError) GetCode

func (a ApiError) GetCode() int

func (ApiError) GetMessage

func (a ApiError) GetMessage() string

func (ApiError) WithCause

func (r ApiError) WithCause(err error) *ApiError

type ApiParams

type ApiParams func(req *ApiRequest)

func AddHead

func AddHead(head map[string]string) ApiParams

func SetAccessory

func SetAccessory(accessory command.Accessory) ApiParams

func SetJsonParamsWithStruct

func SetJsonParamsWithStruct(params interface{}) ApiParams

func SetParams

func SetParams(params []byte) ApiParams

type ApiRequest

type ApiRequest struct {
	// contains filtered or unexported fields
}

func NewApiRequest

func NewApiRequest(params ...ApiParams) *ApiRequest

func (*ApiRequest) GetAccessory

func (r *ApiRequest) GetAccessory() command.Accessory

func (*ApiRequest) Head

func (r *ApiRequest) Head(key string) (val string, exist bool)

func (ApiRequest) IsParamEmpty

func (r ApiRequest) IsParamEmpty() bool

func (*ApiRequest) JsonScan

func (r *ApiRequest) JsonScan(dest interface{}) error

func (*ApiRequest) TakeParams

func (r *ApiRequest) TakeParams() []byte

type ApiResponse

type ApiResponse struct {
	// contains filtered or unexported fields
}

no thread safely

func Response

func Response() *ApiResponse

func ResponseData

func ResponseData(data []byte) *ApiResponse

func ResponseDataString

func ResponseDataString(data string) *ApiResponse

func (*ApiResponse) GetAccessory

func (r *ApiResponse) GetAccessory() (accessory command.Accessory)

func (*ApiResponse) GetData

func (r *ApiResponse) GetData() []byte

func (*ApiResponse) GetJsonData added in v0.0.10

func (r *ApiResponse) GetJsonData(s interface{}) error

func (*ApiResponse) Head

func (r *ApiResponse) Head() map[string]string

func (*ApiResponse) IsEmpty

func (r *ApiResponse) IsEmpty() bool

func (*ApiResponse) SetAccessory

func (r *ApiResponse) SetAccessory(accessory command.Accessory)

func (*ApiResponse) SetHead

func (r *ApiResponse) SetHead(key, val string) (elem string, exist bool)

type ApiServiceCaller

type ApiServiceCaller interface {
	Call(ctx context.Context, funcId string, req *ApiRequest, opts ...CallOption) (resp *ApiResponse, err *ApiError)
}

type ApiServiceFunc

type ApiServiceFunc func(request ApiRequest) (response *ApiResponse, apiError *ApiError)

type ApiServiceRegistry

type ApiServiceRegistry struct {
	// contains filtered or unexported fields
}

func NewApiServiceRegistry

func NewApiServiceRegistry(opts ...RegistryOption) *ApiServiceRegistry

func (*ApiServiceRegistry) ObtainServiceCaller

func (r *ApiServiceRegistry) ObtainServiceCaller(srvId string) (ApiServiceCaller, error)

func (*ApiServiceRegistry) Registry

func (r *ApiServiceRegistry) Registry(srv ApiServicer) error

func (*ApiServiceRegistry) RegistryFunc

func (r *ApiServiceRegistry) RegistryFunc(name string, srvfunc ApiServiceFunc) error

func (*ApiServiceRegistry) Registryies

func (r *ApiServiceRegistry) Registryies(srvs ...ApiServicer)

type ApiServicer

type ApiServicer interface {
	ApiName() string
}

type CallOption

type CallOption interface {
}

type RegistryOption

type RegistryOption interface {
	// contains filtered or unexported methods
}
type registryOption struct {
	zlog *zap.Logger
}

func RegistryLogger

func RegistryLogger(log *zap.Logger) RegistryOption

Jump to

Keyboard shortcuts

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