...

Source file src/github.com/go-kit/kit/endpoint/endpoint.go

Documentation: github.com/go-kit/kit/endpoint

     1  package endpoint
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  // Endpoint is the fundamental building block of servers and clients.
     8  // It represents a single RPC method.
     9  type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error)
    10  
    11  // Nop is an endpoint that does nothing and returns a nil error.
    12  // Useful for tests.
    13  func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }
    14  
    15  // Middleware is a chainable behavior modifier for endpoints.
    16  type Middleware func(Endpoint) Endpoint
    17  
    18  // Chain is a helper function for composing middlewares. Requests will
    19  // traverse them in the order they're declared. That is, the first middleware
    20  // is treated as the outermost middleware.
    21  func Chain(outer Middleware, others ...Middleware) Middleware {
    22  	return func(next Endpoint) Endpoint {
    23  		for i := len(others) - 1; i >= 0; i-- { // reverse
    24  			next = others[i](next)
    25  		}
    26  		return outer(next)
    27  	}
    28  }
    29  
    30  // Failer may be implemented by Go kit response types that contain business
    31  // logic error details. If Failed returns a non-nil error, the Go kit transport
    32  // layer may interpret this as a business logic error, and may encode it
    33  // differently than a regular, successful response.
    34  //
    35  // It's not necessary for your response types to implement Failer, but it may
    36  // help for more sophisticated use cases. The addsvc example shows how Failer
    37  // should be used by a complete application.
    38  type Failer interface {
    39  	Failed() error
    40  }
    41  

View as plain text