在微型项目中制作原型抛出错误 Expected "{" in windows 10
make proto in micro project throws error Expected "{" in windows 10
从 micro and everything works fine. I dont have VisualStudio, but instead I have make
through chocolatey 开始(不知道是否是问题所在)
我bootstrap这样的服务micro new
λ 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
已安装依赖项,一切正常。然后我转到 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 也很好,但我不知道问题出在哪里。
编辑:这是我的原型,由 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;
}
在阅读了一些基础知识后,我发现了问题所在。即使 proto 文件是由 micro 生成的,第 7 行的代码 service Proto.Test
也是问题所在,因为点。我的意思是,用 service Test
替换它解决了这个问题。现在我不知道为什么。任何解释都会被预测。顺便说下我在windows
Go 包名称不能包含点 - 它不会编译:
$ cat pkg.go
package dot.test
$ go build
./pkg.go:1:12: syntax error: unexpected .
因此必须确保生成的代码生成有效的 Go 包名称。
从Go spec
开始,package clause定义为:
A package clause begins each source file and defines the package to
which the file belongs.
PackageClause = "package" PackageName .
PackageName = identifier .
和一个 identifier 作为:
... a sequence of one or more letters and digits. The first
character in an identifier must be a letter.
identifier = letter { letter | unicode_digit } .
从 micro and everything works fine. I dont have VisualStudio, but instead I have make
through chocolatey 开始(不知道是否是问题所在)
我bootstrap这样的服务micro new
λ 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
已安装依赖项,一切正常。然后我转到 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 也很好,但我不知道问题出在哪里。
编辑:这是我的原型,由 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;
}
在阅读了一些基础知识后,我发现了问题所在。即使 proto 文件是由 micro 生成的,第 7 行的代码 service Proto.Test
也是问题所在,因为点。我的意思是,用 service Test
替换它解决了这个问题。现在我不知道为什么。任何解释都会被预测。顺便说下我在windows
Go 包名称不能包含点 - 它不会编译:
$ cat pkg.go
package dot.test
$ go build
./pkg.go:1:12: syntax error: unexpected .
因此必须确保生成的代码生成有效的 Go 包名称。
从Go spec
开始,package clause定义为:
A package clause begins each source file and defines the package to which the file belongs.
PackageClause = "package" PackageName .
PackageName = identifier .
和一个 identifier 作为:
... a sequence of one or more letters and digits. The first character in an identifier must be a letter.
identifier = letter { letter | unicode_digit } .