Carlos Gonzalez
Carlos Gonzalez

Reputation: 151

make proto in micro project throws error Expected "{" in windows 10

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

Upvotes: -1

Views: 1041

Answers (2)

colm.anseo
colm.anseo

Reputation: 22027

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

Upvotes: 2

Carlos Gonzalez
Carlos Gonzalez

Reputation: 151

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

Upvotes: 0

Related Questions