英文:
make proto in micro project throws error Expected "{" in windows 10
问题
从micro开始,一切都正常工作。我没有VisualStudio,但我通过chocolatey安装了make
(不知道是否可能是问题)。
我使用以下命令引导服务:
λ micro new my.test
Creating service my.test
.
├── micro.mu
├── main.go
├── generate.go
├── handler
│ └── my.test.go
├── proto
│ └── my.test.proto
├── Dockerfile
├── Makefile
├── README.md
├── .gitignore
└── go.mod
下载protoc zip包(protoc-$VERSION-$PLATFORM.zip)并安装:
访问https://github.com/protocolbuffers/protobuf/releases
下载用于micro的protobuf:
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
编译proto文件my.test.proto:
cd my.test
make proto
安装依赖项,一切都正常。然后我进入my.test目录,在运行make proto
之后出现了以下错误:
protoc --proto_path=. --micro_out=. --go_out=:. proto/proto.test.proto
proto/proto.test.proto:7:14: Expected "{"
make: *** [Makefile:16: proto] Error 1
我已经安装了所有依赖项,并且我的PATH设置正确,但我不知道问题出在哪里。
编辑:这是我的proto文件,由micro方便地生成:
syntax = "proto3";
package proto.test;
option go_package = "./proto;proto.test";
service Proto.Test {
rpc Call(Request) returns (Response) {}
rpc Stream(StreamingRequest) returns (stream StreamingResponse) {}
rpc PingPong(stream Ping) returns (stream Pong) {}
}
message Message {
string say = 1;
}
message Request {
string name = 1;
}
message Response {
string msg = 1;
}
message StreamingRequest {
int64 count = 1;
}
message StreamingResponse {
int64 count = 1;
}
message Ping {
int64 stroke = 1;
}
message Pong {
int64 stroke = 1;
}
英文:
Starting with micro and everything works fine. I dont have VisualStudio, but instead I have make
through chocolatey(dont know if could be the issue)
I bootstrap the service with micro new
like this.
λ micro new my.test
Creating service my.test
.
├── micro.mu
├── main.go
├── generate.go
├── handler
│   └── my.test.go
├── proto
│   └── my.test.proto
├── Dockerfile
├── Makefile
├── README.md
├── .gitignore
└── go.mod
download protoc zip packages (protoc-$VERSION-$PLATFORM.zip) and install:
visit https://github.com/protocolbuffers/protobuf/releases
download protobuf for micro:
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
compile the proto file my.test.proto:
cd my.test
make proto
Installed dependencies and everything was fine. Then I moved to my.test and after make proto
this error shows up
protoc --proto_path=. --micro_out=. --go_out=:. proto/proto.test.proto
proto/proto.test.proto:7:14: Expected "{".
make: *** [Makefile:16: proto] Error 1
I have all dependencies and my PATH is fine, but I dnt know what the problem is.
Edit: This is my proto, conveniently generated by micro
syntax = "proto3";
package proto.test;
option go_package = "./proto;proto.test";
service Proto.Test {
rpc Call(Request) returns (Response) {}
rpc Stream(StreamingRequest) returns (stream StreamingResponse) {}
rpc PingPong(stream Ping) returns (stream Pong) {}
}
message Message {
string say = 1;
}
message Request {
string name = 1;
}
message Response {
string msg = 1;
}
message StreamingRequest {
int64 count = 1;
}
message StreamingResponse {
int64 count = 1;
}
message Ping {
int64 stroke = 1;
}
message Pong {
int64 stroke = 1;
}
答案1
得分: 2
Go包的名称不能包含点号 - 这样只会导致编译错误:
$ cat pkg.go
package dot.test
$ go build
./pkg.go:1:12: 语法错误: 意外的 .
因此,必须确保生成的代码产生一个有效的Go包名称。
根据Go规范中的package clause的定义:
> 包子句在每个源文件中开始,并定义文件所属的包。
PackageClause = "package" PackageName .
PackageName = identifier .
以及identifier的定义为:
> ... 一个或多个字母和数字的序列。标识符中的第一个字符必须是字母。
identifier = letter { letter | unicode_digit } .
英文:
Go package names cannot contain dots - it will just not compile:
$ cat pkg.go
package dot.test
$ go build
./pkg.go:1:12: syntax error: unexpected .
so one has to ensure generated code produces a valid Go package name.
From the Go spec
, the package clause is defined as:
> A package clause begins each source file and defines the package to
> which the file belongs.
PackageClause = "package" PackageName .
PackageName = identifier .
and an identifier as:
> ... a sequence of one or more letters and digits. The first
> character in an identifier must be a letter.
identifier = letter { letter | unicode_digit } .
答案2
得分: 0
在阅读了一些基础知识后,我找到了问题所在。即使proto文件是由微服务生成的,第七行的代码service Proto.Test
是问题所在,因为有一个点。我的意思是,将其替换为service Test
解决了这个问题。现在我不知道为什么。如果能给出任何解释,我将不胜感激。顺便说一下,我在使用Windows。
英文:
After some reading of the basics I found the problem. Even if the proto file is generated by micro this code service Proto.Test
at line seven is the problem, because of the dot. I mean, replacing that for service Test
solved the issue. Now I dont know why. Any explanation would be preciated. I am in windows by the way
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论