使用Go Kit时出现编译错误。

huangapple go评论99阅读模式
英文:

Compilation Error with go Kit

问题

我克隆了一个使用go-kit的项目,当我尝试编译该项目时,我遇到了一个编译错误,大致如下:

./main.go:124: 无法将makePostEndpoint(svc)(类型为endpoint.Endpoint)作为参数传递给"github.com/go-kit/kit/transport/http".NewServer中的类型"github.com/go-kit/kit/transport/http".DecodeRequestFunc

以下是代码片段:

func main() {
    ctx := context.Background()
    svc := cayleyService{}

    postHandler := httptransport.NewServer(
        ctx,
        makePostEndpoint(svc),
        decodePostRequest,
        encodeResponse,
    )
}

func makeGetEndpoint(svc CayleyService) endpoint.Endpoint {
    return func(ctx context.Context, request interface{}) (interface{}, error) {
        req := request.(getRequest)
        v, err := svc.Get(req.Qu)
        if err != nil {
            return getResponse{v, err.Error()}, nil
        }
        return getResponse{v, ""}, nil
    }
}

我安装的是1.8.1版本的Go语言。

英文:

I cloned a project which uses go-kit, when I try to compile the project, I get an compilation error which is something like

./main.go:124: cannot use makePostEndpoint(svc) (type endpoint.Endpoint) as type "github.com/go-kit/kit/transport/http".DecodeRequestFunc in argument to "github.com/go-k
it/kit/transport/http".NewServer

The snippet of code is as below

func main() {
	ctx := context.Background()
	svc := cayleyService{}

	postHandler := httptransport.NewServer(
		ctx,
		makePostEndpoint(svc),
		decodePostRequest,
		encodeResponse,
	)
}

func makeGetEndpoint(svc CayleyService) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(getRequest)
		v, err := svc.Get(req.Qu)
		if err != nil {
			return getResponse{v, err.Error()}, nil
		}
		return getResponse{v, ""}, nil
	}
}

I have version 1.8.1 of golang installed.

答案1

得分: 1

我找到了问题所在。有一个更新版本的go kit,其中NewServer的签名已经改变。上下文已被移除,因此我只需要移除ctx,然后一切都编译通过了。

英文:

I found the issue. There is a newer version of go kit in which the signature of the NewServer has changed. Context has been removed and hence. I just had to remove the ctx and everything compiled.

huangapple
  • 本文由 发表于 2017年6月8日 01:20:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/44419068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定