apicommon

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidResults       = errors.New("invalid results")
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
)
View Source
var DebugMode bool

Functions

func BytesToString added in v0.8.0

func BytesToString(bytes []byte) string

func ClientShouldReportError added in v0.8.4

func ClientShouldReportError(err error, statusCode int) bool

func FillIncomingRPCFiltersTable added in v0.8.0

func FillIncomingRPCFiltersTable(rpcFiltersTable [][]IncomingRPCHandler, rpcFilters map[int][]IncomingRPCHandler)

func FillOutgoingRPCFiltersTable added in v0.8.0

func FillOutgoingRPCFiltersTable(rpcFiltersTable [][]OutgoingRPCHandler, rpcFilters map[int][]OutgoingRPCHandler)

func HandleOutgoingRPC added in v0.8.0

func HandleOutgoingRPC(ctx context.Context, outgoingRPC *OutgoingRPC) error

func HandleRequest added in v0.8.0

func HandleRequest(
	request *http.Request,
	incomingRPC *IncomingRPC,
	traceIDGenerator TraceIDGenerator,
	responseWriter http.ResponseWriter,
)

func MakeContextWithIncomingRPC added in v0.8.0

func MakeContextWithIncomingRPC(ctx context.Context, incomingRPC *IncomingRPC) context.Context

func MakeInMemoryTransport added in v0.8.0

func MakeInMemoryTransport(handler http.Handler) http.RoundTripper

func ServerShouldReportError added in v0.8.4

func ServerShouldReportError(err error, statusCode int) bool

Types

type ActorOptions added in v0.8.3

type ActorOptions struct {
	RPCFilters       map[int][]IncomingRPCHandler
	TraceIDGenerator TraceIDGenerator
}

func (*ActorOptions) AddCommonRPCFilters added in v0.8.3

func (ao *ActorOptions) AddCommonRPCFilters(rpcFilters ...IncomingRPCHandler)

func (*ActorOptions) AddRPCFilters added in v0.8.3

func (ao *ActorOptions) AddRPCFilters(methodIndex int, rpcFilters ...IncomingRPCHandler)

func (*ActorOptions) Sanitize added in v0.8.3

func (ao *ActorOptions) Sanitize()

type ClientOptions

type ClientOptions struct {
	RPCFilters map[int][]OutgoingRPCHandler
	Timeout    time.Duration
	Transport  http.RoundTripper
}

func (*ClientOptions) AddCommonRPCFilters added in v0.8.0

func (co *ClientOptions) AddCommonRPCFilters(rpcFilters ...OutgoingRPCHandler)

func (*ClientOptions) AddRPCFilters added in v0.8.0

func (co *ClientOptions) AddRPCFilters(methodIndex int, rpcFilters ...OutgoingRPCHandler)

func (*ClientOptions) Sanitize

func (co *ClientOptions) Sanitize()

type DummyFurtherValidator

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

func (DummyFurtherValidator) FurtherValidate

func (DummyFurtherValidator) FurtherValidate(*ValidationContext) bool

type DummyModel added in v0.8.0

type DummyModel struct{}

func (DummyModel) Validate added in v0.8.0

func (DummyModel) Validate(*ValidationContext) bool

type Error

type Error struct {
	Code       ErrorCode `json:"-"`
	StatusCode int       `json:"-"`
	Message    string    `json:"message"`
	Details    string    `json:"details,omitempty"`
	Data       ErrorData `json:"data,omitempty"`
}

func NewInvalidParamsError

func NewInvalidParamsError() *Error

func NewNotImplementedError

func NewNotImplementedError() *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Temporary added in v0.8.0

func (e *Error) Temporary() bool

type ErrorCode

type ErrorCode int32
const ErrorInvalidParams ErrorCode = 2
const ErrorNotImplemented ErrorCode = 1

type ErrorData

type ErrorData map[string]interface{}

func (ErrorData) ClearValue

func (ed ErrorData) ClearValue(key string)

func (ErrorData) GetValue

func (ed ErrorData) GetValue(key string) (interface{}, bool)

func (*ErrorData) SetValue

func (ed *ErrorData) SetValue(key string, value interface{})

type FurtherValidator

type FurtherValidator interface {
	FurtherValidate(validationContext *ValidationContext) (ok bool)
}

type IncomingRPC

type IncomingRPC struct {
	Namespace      string
	ServiceName    string
	MethodName     string
	FullMethodName string
	MethodIndex    int
	Params         Model
	Results        Model

	RemoteIP       string
	InboundHeader  http.Header
	OutboundHeader http.Header
	TraceID        string
	RawParams      []byte
	StatusCode     int
	ErrorCode      ErrorCode
	RawResults     []byte
	// contains filtered or unexported fields
}

func GetIncomingRPCFromContext added in v0.8.0

func GetIncomingRPCFromContext(ctx context.Context) (*IncomingRPC, bool)

func (*IncomingRPC) Do added in v0.8.0

func (ir *IncomingRPC) Do(ctx context.Context) (returnedErr error)

func (*IncomingRPC) EncodeResults added in v0.8.0

func (ir *IncomingRPC) EncodeResults() error

func (*IncomingRPC) LoadParams added in v0.8.0

func (ir *IncomingRPC) LoadParams(ctx context.Context) error

func (*IncomingRPC) ReadRawParams added in v0.8.0

func (ir *IncomingRPC) ReadRawParams() error

func (*IncomingRPC) SetFilters added in v0.8.0

func (ir *IncomingRPC) SetFilters(filters []IncomingRPCHandler)

func (*IncomingRPC) SetHandler added in v0.8.0

func (ir *IncomingRPC) SetHandler(handler IncomingRPCHandler)

func (*IncomingRPC) SetReader added in v0.8.0

func (ir *IncomingRPC) SetReader(reader io.Reader)

type IncomingRPCHandler added in v0.8.0

type IncomingRPCHandler func(ctx context.Context, incomingRPC *IncomingRPC) (err error)

type Model

type Model interface {
	Validate(validationContext *ValidationContext) (ok bool)
}

type OutgoingRPC

type OutgoingRPC struct {
	Namespace      string
	ServiceName    string
	MethodName     string
	FullMethodName string
	MethodIndex    int
	Params         Model
	Results        Model

	Transport      http.RoundTripper
	URL            string
	OutboundHeader http.Header
	RawParams      []byte
	StatusCode     int
	InboundHeader  http.Header
	TraceID        string
	ErrorCode      ErrorCode
	RawResults     []byte
	// contains filtered or unexported fields
}

func (*OutgoingRPC) Do added in v0.8.0

func (or *OutgoingRPC) Do(ctx context.Context) error

func (*OutgoingRPC) EncodeParams added in v0.8.0

func (or *OutgoingRPC) EncodeParams() error

func (*OutgoingRPC) LoadResults added in v0.8.0

func (or *OutgoingRPC) LoadResults(ctx context.Context) error

func (*OutgoingRPC) ReadRawResults added in v0.8.0

func (or *OutgoingRPC) ReadRawResults() error

func (*OutgoingRPC) SetFilters added in v0.8.0

func (or *OutgoingRPC) SetFilters(filters []OutgoingRPCHandler)

func (*OutgoingRPC) SetHandler added in v0.8.0

func (or *OutgoingRPC) SetHandler(handler OutgoingRPCHandler)

func (*OutgoingRPC) SetReadCloser added in v0.8.0

func (or *OutgoingRPC) SetReadCloser(readCloser io.ReadCloser)

type OutgoingRPCHandler added in v0.8.0

type OutgoingRPCHandler func(ctx context.Context, outgoingRPC *OutgoingRPC) (err error)

type ReaderFunc added in v0.8.0

type ReaderFunc func(buffer []byte) (dataSize int, err error)

func (ReaderFunc) Read added in v0.8.0

func (rf ReaderFunc) Read(buffer []byte) (int, error)

type RouteInfo

type RouteInfo struct {
	RPCPath        string
	FullMethodName string
	RPCFilters     []string
}

type Router

type Router struct {
	NotFoundHandler http.Handler
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) AddRoute

func (r *Router) AddRoute(
	rpcPath string,
	handler http.Handler,
	fullMethodName string,
	rpcFilters []IncomingRPCHandler,
)

func (*Router) RouteInfos

func (r *Router) RouteInfos() []RouteInfo

func (*Router) ServeHTTP added in v0.6.0

func (r *Router) ServeHTTP(w http.ResponseWriter, rr *http.Request)

type TraceIDGenerator

type TraceIDGenerator func() (traceID string)

type TransportFunc

type TransportFunc func(request *http.Request) (response *http.Response, err error)

func (TransportFunc) RoundTrip

func (tf TransportFunc) RoundTrip(request *http.Request) (*http.Response, error)

type ValidationContext

type ValidationContext struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

func NewValidationContext

func NewValidationContext(ctx context.Context) *ValidationContext

func (*ValidationContext) Enter

func (vc *ValidationContext) Enter(pathComponent string)

func (*ValidationContext) ErrorDetails

func (vc *ValidationContext) ErrorDetails() string

func (*ValidationContext) Leave

func (vc *ValidationContext) Leave()

func (*ValidationContext) SetErrorDetails

func (vc *ValidationContext) SetErrorDetails(errorDetails string)

Jump to

Keyboard shortcuts

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