英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论