Introductng the WeGO framework pipeline.
Edit me

Introduction

The WeGO framework establishes a pipeline for every registered service. Each registered service is invoked at the end of the pipeline.

Let us look at an illustration of the server side pipeline

Wego Server Side Pipeline

The pipeline starts with an entry point and ends with the terminator. There are middlewares that can be inserted in the pipeline. The terminator is a middleware.

Entry Point

However, the entry point has the following signature

Entrypoint(ctx context.Context) (interface{}, error)

It accepts a context and returns the response along with error if any. In the context of HTTP the context has been prepared with the contents of the HTTP request. Context consists of a set of name, value pairs. The important keys in context are:

  • Operation Descriptor: This key indicates the operation that needs to be invoked by this entry point.
  • Payload: This contains the payload of the request. It is accepted as a ReadCloser typically. But it can be anything. The request payload is used to invoke the service ultimately.
  • Other Header attributes: These header attributes are passed as HTTP headers or query or path params. These might be used by various middlewares to implement horizontal requirements.
  • Response Payload: (Used in the return path) This is the payload that was generated by the service in the response. (Used in the return path)This is the response that is returned by the Entrypoint.
  • Error: This is the error that is ultimately returned by the Entry point.

The entry point constructs the pipeline with the appropriate middleware. The following middlewares are inserted:

  • Decoder This converts the request payload to the ultimate payload accepted by the service.
  • Validator: This validates the incoming payload for any discrepancies. The request payload has tag information that is used to perform the validation by the v10 framework.

Other middlewares are service-operation specific and are specified by the Operation Descriptor. The last middleware inserted by the entry point is the terminator.

Terminator

The terminator is the last middleware and invokes the operation. Each parameter that needs to be passed to the operation is constructed from the context. Appropriate keys are picked up for each of the parameters. The first parameter of all operations is the entire context object. There can be header parameters that utilize various keys in the context. Each key is read from the context as a string and converted to the appropriate type as specified in ParamDescriptor.ParamKind.

The payload parameter is picked up from the Payload key specified above.

The Proxy Pipeline

The proxy pipeline is illustrated below: proxy pipeline

The pipeline starts with a proxy entry point and ends with the http invoker.

HTTP Proxy Entry Point

This has the signature as:

ProxyEntrypoint(ctx context.Context, od fw.OperationDescriptor, params ...interface{}) (interface{}, error)

The context passed must have all the headers that are required to be sent via HTTP. The operation descriptor must contain information about the service that needs to be remotely accessed. The params contains the actual params that need to be passed to the service

The HTTP entry point puts all the information in the context from the params either as individual HEADER keys or the payload key depending on the configuration in the Operation descriptor.

It sets up the pipeline with proxy middlewares specified in the operation descriptor. The last middleware inserted is the http invoker.

The Proxy Pipeline Terminator - http-invoker

The http-invoker is responsible for invoking the service. Please see additional notes in the HTTP module