Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binder ¶
Binder performs the work of taking all meaningful values from an incoming request (body, path params, query string) and applying them to a Go struct (likely the "XxxRequest" for your service method).
type Client ¶
type Client struct {
// HTTP takes care of the raw HTTP request/response logic used when communicating w/ remote services.
HTTP *http.Client
// BaseURL contains the protocol/host/port/etc that is the prefix for all service function
// endpoints. (e.g. "http://api.myawesomeapp.com")
BaseURL string
// PathPrefix sits between the host/port and the endpoint path (e.g. something like "v2") so that
// you can segment/version your services. Typically this will be the same as what you apply as
// the gateway's path prefix.
PathPrefix string
// Name is just the display name of the service; used only for debugging/tracing purposes.
Name string
// contains filtered or unexported fields
}
Client manages all RPC communication with other frodo-powered services. It uses HTTP under the hood, so you can supply a custom HTTP client by including WithHTTPClient() when calling your client constructor, NewXxxServiceClient().
func NewClient ¶
func NewClient(name string, addr string, options ...ClientOption) Client
NewClient constructs the RPC client that does the "heavy lifting" when communicating with remote frodo-powered RPC services. It contains all data/logic required to marshal/unmarshal requests/responses as well as communicate w/ the remote service.
func (Client) Invoke ¶
func (c Client) Invoke(ctx context.Context, method string, path string, serviceRequest interface{}, serviceResponse interface{}) error
Invoke handles the standard request/response logic used to call a service method on the remote service. You should NOT call this yourself. Instead, you should stick to the strongly typed, code-generated service functions on your client.
type ClientMiddlewareFunc ¶
type ClientMiddlewareFunc func(request *http.Request, next RoundTripperFunc) (*http.Response, error)
ClientMiddlewareFunc is a round-tripper-like function that accepts a request and returns a response/error combo, but also accepts 'next' (the rest of the computation) so that you can short circuit the execution as you see fit.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a single configurable setting that modifies some attribute of the RPC client when building one via NewClient().
func WithClientMiddleware ¶
func WithClientMiddleware(funcs ...ClientMiddlewareFunc) ClientOption
WithClientMiddleware sets the chain of HTTP request/response handlers you want to invoke on each service function invocation before/after we dispatch the HTTP request.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient allows you to provide an HTTP client configured to your liking. You do not *need* to supply this. The default client already implements a 30 second timeout, but if you want a different timeout or custom dialer/transport/etc, then you can feed in you custom client here and we'll use that one for all HTTP communication with other services.
type CompositeGateway ¶
type CompositeGateway struct {
// Name is a colon-separated string containing the names of all of the services wrapped up in here.
Name string
// Gateways tracks all of the original gateways that this is wrapping up.
Gateways []Gateway
// Router is the HTTP mux that does the actual request routing work.
Router *httptreemux.TreeMux
// contains filtered or unexported fields
}
CompositeGateway is a gateway that is composed of multiple service RPC Gateway instances. You use one of these when you want to run multiple services in the same process (like for local dev).
func Compose ¶
func Compose(gateways ...Gateway) CompositeGateway
Compose accepts multiple gateways generated using the 'frodo' tool in order to allow them to run in the same HTTP server/listener. A typical use-case for this functionality is when you are running microservices in local development. Rather than starting/stopping 20 different processes, you can run all of your services in a single server process:
userGateway := users.NewUserServiceGateway(userService)
groupGateway := groups.NewGroupServiceGateway(groupService)
projectGateway := projects.NewProjectServiceGateway(projectService)
gateway := rpc.Compose(
userGateway,
groupGateway,
projectGateway,
)
http.listenAndService(":8080", gateway)
This will preserve all of the original gateways as well. Now you'll just have a "master" gateway that contains all of the routes/endpoints from all of the services.
func (CompositeGateway) ServeHTTP ¶
func (gw CompositeGateway) ServeHTTP(w http.ResponseWriter, req *http.Request)
type Endpoint ¶
type Endpoint struct {
// The HTTP method that should be used when exposing this endpoint in the gateway.
Method string
// The HTTP path pattern that should be used when exposing this endpoint in the gateway.
Path string
// ServiceName is the name of the service that this operation is part of.
ServiceName string
// Name is the name of the function/operation that this endpoint describes.
Name string
// Handler is the gateway function that does the "work".
Handler http.HandlerFunc
}
Endpoint describes an operation that we expose through an RPC gateway.
func EndpointFromContext ¶
EndpointFromContext fetches the meta information about the service RPC operation that we're currently invoking.
type Gateway ¶
type Gateway struct {
Name string
Router *httptreemux.TreeMux
Binder Binder
PathPrefix string
// contains filtered or unexported fields
}
Gateway wrangles all of the incoming RPC/HTTP handling for your service calls. It automatically converts all transport data into your Go request struct. Conversely, it also marshals and transmits your service response struct data back to the caller. Aside from feeding this to `http.ListenAndServe()` you likely won't interact with this at all yourself.
func NewGateway ¶
func NewGateway(options ...GatewayOption) Gateway
NewGateway creates a wrapper around your raw service to expose it via HTTP for RPC calls.
type GatewayOption ¶
type GatewayOption func(*Gateway)
GatewayOption defines a setting you can apply when creating an RPC gateway via 'NewGateway'.
func WithBinder ¶
func WithBinder(binder Binder) GatewayOption
WithBinder allows you to override a Gateway's default binding behavior with the custom behavior of your choice.
func WithMiddleware ¶
func WithMiddleware(mw ...MiddlewareFunc) GatewayOption
WithMiddleware invokes this chain of work before executing the actual HTTP handler for your service call. Any functions yu supply here will fire before your service function, but after built-in middleware functions such as the one that restores metadata (i.e. your middleware will have access to request/context metadata).
type MiddlewareFunc ¶
type MiddlewareFunc func(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
MiddlewareFunc is a component that conforms to the 'negroni' middleware function. It accepts the standard HTTP inputs as well as the rest of the computation.
func (MiddlewareFunc) ServeHTTP ¶
func (mw MiddlewareFunc) ServeHTTP(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
ServeHTTP basically calls itself. This is a mechanism that lets middleware functions be passed around the same as a full middleware handler component.
type RoundTripperFunc ¶
RoundTripperFunc matches the signature of the standard http.RoundTripper interface.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package errors provides a curated list of standard types of failures you'll likely encounter when executing RPC handlers.
|
Package errors provides a curated list of standard types of failures you'll likely encounter when executing RPC handlers. |
|
Package metadata provides request-scoped values for your RPC calls.
|
Package metadata provides request-scoped values for your RPC calls. |