Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4797

How are we passing context while creating endpoint in go-kit

$
0
0
func MakeGetEndpoint(srv Service) endpoint.Endpoint {    return func(ctx context.Context, request interface{}) (interface{}, error) {        _ = request.(getRequest) // we really just need the request, we don't use any value from it        d, err := srv.Get(ctx)        if err != nil {            return getResponse{d, err.Error()}, nil        }        return getResponse{d, ""}, nil    }}
    // mapping endpoints    endpoints := napodate.Endpoints{        GetEndpoint:      napodate.MakeGetEndpoint(srv)    }
func (e Endpoints) Get(ctx context.Context) (string, error) {    req := getRequest{}    resp, err := e.GetEndpoint(ctx, req)    if err != nil {        return "", err    }    getResp := resp.(getResponse)    if getResp.Err != "" {        return "", errors.New(getResp.Err)    }    return getResp.Date, nil}

How are we ensuring the ctx used during e.GetEndpoint(ctx, req) is the same ctx that is used in MakeEndpoint. I understand that they are mapped but what does this mapping actually mean since MakeGetEndpoint only accepts srv parameter but GetEndpoint passes ctx and req.Also, when is MakeEndpoint getting actually executed and how it gets access to srv, ctx and request.


Viewing all articles
Browse latest Browse all 4797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>