Codebase list golang-github-go-kit-kit / 1f9491d addsvc / endpoint.go
1f9491d

Tree @1f9491d (Download .tar.gz)

endpoint.go @1f9491draw · history · blame

package main

import (
	"golang.org/x/net/context"

	"github.com/go-kit/kit/addsvc/reqrep"
	"github.com/go-kit/kit/endpoint"
)

// makeEndpoint returns an endpoint wrapping the passed Add. If Add were an
// interface with multiple methods, we'd need individual endpoints for each.
//
// This function is just boiler-plate; in theory, it could be generated.
func makeEndpoint(a Add) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		select {
		default:
		case <-ctx.Done():
			return nil, endpoint.ErrContextCanceled
		}

		addReq, ok := request.(reqrep.AddRequest)
		if !ok {
			println("### 1")
			return nil, endpoint.ErrBadCast
		}

		v := a(ctx, addReq.A, addReq.B)

		return reqrep.AddResponse{V: v}, nil
	}
}