package
0.0.0-20241001120344-791233ab31d1
Repository: https://github.com/wearemojo/mojo-public-go.git
Documentation: pkg.go.dev
# README
crpc
crpc provides a simple abstraction for RPC clients and servers.
It is heavily influenced by net/rpc and Monzo Typhon.
Components
crpc consists of a Client and a Server component.
Client
The Client component is not intended to be used directly, but to be composed into a more fully-featured service client.
See example/client/ for example usage.
Server
The Server component is intended to be used directly, and have handlers associated directly with it.
It implements net/http.Handler
, thus can be embedded directly within an HTTP server. This is in preparation of enabling TLS between service, and thus internal RPC can use HTTP/2 multiplexing.
See example/server/ for example usage.
# Packages
No description provided by the author
# Functions
No description provided by the author
GetRequestContext returns the Request from the context object.
Logger inherits the context logger and reports RPC request success/failure.
MustWrap is the same as Wrap, however it panics when passed an invalid handler.
NewClient returns a client configured with a transport scheme, remote host and URL prefix supplied as a URL <scheme>://<host></prefix>.
NewServer returns a new RPC Server with an optional exception tracker.
NoLongerSupported is a HandlerFunc which always returns the error `no_longer_supported` to the requester to indicate methods which have been withdrawn.
Validate buffers the JSON body and applies a JSON Schema validation.
Wrap reflects a HandlerFunc from any function matching the following signatures:
func(ctx context.Context, request *T) (response *T, err error) func(ctx context.Context, request *T) (err error) func(ctx context.Context) (response *T, err error) func(ctx context.Context) (err error).
# Constants
InfraEndpointStatus is the header appended to the response indicating the usability status of the endpoint.
LatestNotice is the contents of the `Infra-Endpoint-Status` header when an endpoint is called to request the latest version.
PreviewNotice is the contents of the `Infra-Endpoint-Status` header when an endpoint is called with the preview version.
StableNotice is the contents of the `Infra-Endpoint-Status` header when an endpoint is called and is not expected to change.
VersionLatest is used by engineers only to call the latest version of an endpoint in utilities like cURL and Paw.
VersionPreview is used for experimental endpoints in development which are coming but a version identifier has not been decided yet or may be withdrawn at any point.
# Structs
Client represents a crpc client.
ClientTransportError is returned when an error related to executing a client request occurs.
Request contains metadata about the RPC request.
Server is an HTTP-compatible crpc handler.
WrappedFunc contains the wrapped handler, and some additional information about the function that was determined during the reflection process.
# Interfaces
ResponseWriter is the destination for RPC responses.
# Type aliases
HandlerFunc defines a handler for an RPC request.
MiddlewareFunc is a function that wraps HandlerFuncs.