endpoint

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyEndpoint added in v1.2.6

type AnyEndpoint Endpoint[any, any]

type AnyEndpointFunc added in v1.2.6

type AnyEndpointFunc EndpointFunc[any, any]

type BusApi added in v1.2.6

type BusApi interface {
	Subscribe(endpointName string, ep AnyEndpoint)
	Dispatch(ctx context.Context, req any) (resp any, err error)
}

type Endpoint

type Endpoint[Req any, Resp any] interface {
	Invoke(ctx context.Context, request Req) (Resp, error)
}

Endpoint represents a single RPC method.

func Chain

func Chain[Q any, R any](ep Endpoint[Q, R], middlewares ...Middleware[Q, R]) Endpoint[Q, R]

Chain decorates the given Endpoint with all middlewares.

type EndpointFunc

type EndpointFunc[Req any, Resp any] func(ctx context.Context, request Req) (Resp, error)

The EndpointFunc type is an adapter to allow the use of ordinary functions as Endpoint.

func (EndpointFunc[Req, Resp]) Invoke

func (f EndpointFunc[Req, Resp]) Invoke(ctx context.Context, request Req) (Resp, error)

Invoke calls f(ctx).

type Middleware

type Middleware[Request any, Response any] interface {
	// Decorate wraps the underlying Endpoint, adding some functionality.
	Decorate(ep Endpoint[Request, Response]) Endpoint[Request, Response]
}

Middleware allows us to write something like decorators to Endpoint. It can execute something before invoke or after.

type MiddlewareFunc

type MiddlewareFunc[Request any, Response any] func(ep Endpoint[Request, Response]) Endpoint[Request, Response]

The MiddlewareFunc type is an adapter to allow the use of ordinary functions as Middleware.

func (MiddlewareFunc[Request, Response]) Decorate

func (f MiddlewareFunc[Request, Response]) Decorate(ep Endpoint[Request, Response]) Endpoint[Request, Response]

Decorate call f(endpoint).

type Noop

type Noop[Req any, Resp any] struct{}

Noop is an endpoint that does nothing and returns a nil error.

func (Noop[Req, Resp]) Invoke

func (Noop[Req, Resp]) Invoke(context.Context, Req) (Resp, error)

Jump to

Keyboard shortcuts

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