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. Also, when is MakeEndpoint getting actually executed and how it gets access to srv, ctx and request.