在微项目中制作原型抛出错误 Windows 10 中的预期"{"



从微开始,一切都很好。我没有VisualStudio,但相反,我有make通过巧克力(不知道如果可能是问题)

我用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

安装了依赖项,一切正常。然后我搬到我的。测试和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是好的,但我不知道问题是什么。

编辑:这是我的原型,方便地生成的微

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;
}

Go包名不能包含点,否则将无法编译:

$ cat pkg.go
package dot.test
$ go build
./pkg.go:1:12: syntax error: unexpected .

所以必须确保生成的代码产生一个有效的Go包名。


Go spec中,package子句定义为:

包子句在每个源文件开始,并定义要使用的包

PackageClause  = "package" PackageName .
PackageName    = identifier .

和标识符:

…一个或多个字母和数字的序列。第一个标识符中的字符必须是字母。

identifier = letter { letter | unicode_digit } .

在阅读了一些基础知识之后,我发现了这个问题。即使原型文件是由微程序生成的,由于网点的原因,第七行的service Proto.Test代码也是有问题的。我的意思是,替换service Test解决了这个问题。现在我不知道为什么。任何解释都是值得感激的。顺便说一下,我在windows

最新更新