Go + Protocol Buffers的行为非常奇怪。

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

Go + Protocol buffers acting really strange

问题

我正在为我正在进行的项目编写一个基于服务的服务器,该项目使用Go语言编写,并使用Protocol Buffers进行服务间通信。一切都运行正常,直到我添加了名为DeviceRequestDeviceResponse的协议,现在编译器找不到它们,尽管协议的Go源代码存在并在我的GOPATH中设置好了。WebStorm也能找到它们,但出于某种原因编译器却找不到。奇怪的是,旧的协议,其Go源代码已经不存在了,却可以正常工作(WebStorm也无法识别它们),请参考这些截图Go + Protocol Buffers的行为非常奇怪。 Go + Protocol Buffers的行为非常奇怪。 Go + Protocol Buffers的行为非常奇怪。

我尝试删除了GOPATH中的文件,但没有起作用。我猜测go可能使用了某种缓存,但我在网上找不到相关信息。

英文:

I'm writing a service-based server for a project I'm working on, which is written in Go and uses Protocol Buffers for inter-service communication. Everything was working fine until I added protocols named DeviceRequest and DeviceResponse, now the compiler can't find them, while the go source of the protocol exists and is set up in my GOPATH. WebStorm also finds them, but for some reason the compiler doesn't. The strange thing is that old protocols of which the Go source doesn't exist anymore do work (Webstorm also does not recognize them), see these screenshots Go + Protocol Buffers的行为非常奇怪。 Go + Protocol Buffers的行为非常奇怪。 Go + Protocol Buffers的行为非常奇怪。

I've tried deleting the files in my GOPATH, but that didn't work. My guess is that go is using some kind of cache memory but I couldn't find anything about that online.

答案1

得分: 1

协议缓冲区(Protocol Buffers)不会自动编译成Go代码,除非你使用第三方工具来完成这个过程。Protocol Buffers中的protoc工具可以用来创建.proto文件的Go实现。生成的代码应该存放在$GOPATH/src目录下,而.a文件则会存放在$GOPATH/pkg目录下。代码补全功能会查找$GOPATH/pkg目录,而"go"工具会在$GOPATH/src目录下查找已更改的内容。

清空$GOPATH/pkg目录的内容,然后运行"go install"命令重新生成.a文件。

英文:

Protocol buffers are not compiled automatically into Go code unless you have a third party tool that does this. The protoc tool that is part of Protocol Buffers would be used to create the Go implementation of the .proto files. The output should reside in your $GOPATH/src. The .a files would be stored under $GOPATH/pkg. The code completion looks at the $GOPATH/pkg whereas the "go" tool would look in $GOPATH/src for anything that had changed.

Remove the contents of $GOPATH/pkg and then run "go install" to recreate the .a files.

huangapple
  • 本文由 发表于 2015年6月9日 03:50:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/30717830.html
匿名

发表评论

匿名网友

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

确定