kit: Index | Examples | Files

package endpoint

import ""

Package endpoint defines an abstraction for RPCs.

Endpoints are a fundamental building block for many Go kit components. Endpoints are implemented by servers, and called by clients.



Package Files

doc.go endpoint.go

func Nop Uses

func Nop(context.Context, interface{}) (interface{}, error)

Nop is an endpoint that does nothing and returns a nil error. Useful for tests.

type Endpoint Uses

type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error)

Endpoint is the fundamental building block of servers and clients. It represents a single RPC method.

type Middleware Uses

type Middleware func(Endpoint) Endpoint

Middleware is a chainable behavior modifier for endpoints.

func Chain Uses

func Chain(outer Middleware, others ...Middleware) Middleware

Chain is a helper function for composing middlewares. Requests will traverse them in the order they're declared. That is, the first middleware is treated as the outermost middleware.


package main

import (


func main() {
    e := endpoint.Chain(

    if _, err := e(ctx, req); err != nil {


var (
    ctx = context.Background()
    req = struct{}{}

func annotate(s string) endpoint.Middleware {
    return func(next endpoint.Endpoint) endpoint.Endpoint {
        return func(ctx context.Context, request interface{}) (interface{}, error) {
            fmt.Println(s, "pre")
            defer fmt.Println(s, "post")
            return next(ctx, request)

func myEndpoint(context.Context, interface{}) (interface{}, error) {
    fmt.Println("my endpoint!")
    return struct{}{}, nil

Package endpoint imports 1 packages (graph) and is imported by 753 packages. Updated 2018-03-13. Refresh now. Tools for package owners.