Protobuf: protoc-gen-go: no service generated

Created on 24 Mar 2019  Â·  15Comments  Â·  Source: golang/protobuf

What version of protobuf and what language are you using?

$ protoc --version
libprotoc 3.7.0

I use go language.

What did you do?

I generated a .pb.go file using proto file:

syntax = "proto3";

import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

message Event {
  google.protobuf.Timestamp created_at = 1;
  string from = 2;
}

service Events {
  rpc Push(Event) returns(google.protobuf.Empty);
}

running following command:

protoc -I . event.proto --go_out=plugins=grpc:.

What did you expect to see?

generated services

What did you see instead?

// Code generated by protoc-gen-go. DO NOT EDIT.
// source: event.proto

package event

import (
    fmt "fmt"
    proto "github.com/golang/protobuf/proto"
    _ "github.com/golang/protobuf/ptypes/empty"
    timestamp "github.com/golang/protobuf/ptypes/timestamp"
    math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package

type Event struct {
    CreatedAt            *timestamp.Timestamp `protobuf:"bytes,1,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
    From                 string               `protobuf:"bytes,2,opt,name=from,proto3" json:"from,omitempty"`
    XXX_NoUnkeyedLiteral struct{}             `json:"-"`
    XXX_unrecognized     []byte               `json:"-"`
    XXX_sizecache        int32                `json:"-"`
}

func (m *Event) Reset()         { *m = Event{} }
func (m *Event) String() string { return proto.CompactTextString(m) }
func (*Event) ProtoMessage()    {}
func (*Event) Descriptor() ([]byte, []int) {
    return fileDescriptor_2d17a9d3f0ddf27e, []int{0}
}

func (m *Event) XXX_Unmarshal(b []byte) error {
    return xxx_messageInfo_Event.Unmarshal(m, b)
}
func (m *Event) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
    return xxx_messageInfo_Event.Marshal(b, m, deterministic)
}
func (m *Event) XXX_Merge(src proto.Message) {
    xxx_messageInfo_Event.Merge(m, src)
}
func (m *Event) XXX_Size() int {
    return xxx_messageInfo_Event.Size(m)
}
func (m *Event) XXX_DiscardUnknown() {
    xxx_messageInfo_Event.DiscardUnknown(m)
}

var xxx_messageInfo_Event proto.InternalMessageInfo

func (m *Event) GetCreatedAt() *timestamp.Timestamp {
    if m != nil {
        return m.CreatedAt
    }
    return nil
}

func (m *Event) GetFrom() string {
    if m != nil {
        return m.From
    }
    return ""
}

func init() {
    proto.RegisterType((*Event)(nil), "Event")
}

func init() { proto.RegisterFile("event.proto", fileDescriptor_2d17a9d3f0ddf27e) }

var fileDescriptor_2d17a9d3f0ddf27e = []byte{
    // 167 bytes of a gzipped FileDescriptorProto
    0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4e, 0x2d, 0x4b, 0xcd,
    0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x97, 0x92, 0x4e, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, 0xd5,
    0x07, 0xf3, 0x92, 0x4a, 0xd3, 0xf4, 0x53, 0x73, 0x0b, 0x4a, 0x2a, 0xa1, 0x92, 0xf2, 0xe8, 0x92,
    0x25, 0x99, 0xb9, 0xa9, 0xc5, 0x25, 0x89, 0xb9, 0x05, 0x10, 0x05, 0x4a, 0x61, 0x5c, 0xac, 0xae,
    0x20, 0xc3, 0x84, 0x2c, 0xb9, 0xb8, 0x92, 0x8b, 0x52, 0x13, 0x4b, 0x52, 0x53, 0xe2, 0x13, 0x4b,
    0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0xa4, 0xf4, 0x20, 0xda, 0xf5, 0x60, 0xda, 0xf5, 0x42,
    0x60, 0xda, 0x83, 0x38, 0xa1, 0xaa, 0x1d, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xd2, 0x8a, 0xf2, 0x73,
    0x25, 0x98, 0x14, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x23, 0x03, 0x2e, 0x36, 0xb0, 0xb9, 0xc5,
    0x42, 0x6a, 0x5c, 0x2c, 0x01, 0xa5, 0xc5, 0x19, 0x42, 0x6c, 0x7a, 0x60, 0x01, 0x29, 0x31, 0x0c,
    0x43, 0x5d, 0x41, 0x0e, 0x4e, 0x62, 0x03, 0xf3, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x35,
    0x77, 0x1d, 0x30, 0xdd, 0x00, 0x00, 0x00,
}

question waiting-for-info

Most helpful comment

In my case, the problem was on my side. I was running --go_out=. instead of --go_out=plugins=grpc:..

There, now everybody on github knows I can't read the documentation. :cry:

All 15 comments

Same here with libprotoc 3.7.1 and protoc v1.3.1

Same here, with libprotoc 3.7.1

Any update on this ?

I am not able to reproduce with either:

  • libprotoc v3.6.1 and protoc-gen-go v1.3.1
  • libprotoc v3.7.0 and protoc-gen-go v1.3.1

These are the exact steps I did:

rawr@khaydarin: ~ $ protoc --version
libprotoc 3.6.1
rawr@khaydarin: ~ $ which protoc-gen-go
rawr@khaydarin: ~ $ GOBIN=~/.bin GO111MODULE=on go get github.com/golang/protobuf/[email protected]
go: finding github.com/golang/protobuf/protoc-gen-go v1.3.1
rawr@khaydarin: ~ $ which protoc-gen-go
/Users/rawr/.bin/protoc-gen-go
rawr@khaydarin: ~ $ protoc -I . event.proto --go_out=plugins=grpc:.
rawr@khaydarin: ~ $ cat event.pb.go | grep grpc
    grpc "google.golang.org/grpc"
var _ grpc.ClientConn
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
    Push(ctx context.Context, in *Event, opts ...grpc.CallOption) (*empty.Empty, error)
    cc *grpc.ClientConn
func NewEventsClient(cc *grpc.ClientConn) EventsClient {
func (c *eventsClient) Push(ctx context.Context, in *Event, opts ...grpc.CallOption) (*empty.Empty, error) {
func RegisterEventsServer(s *grpc.Server, srv EventsServer) {
func _Events_Push_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
    info := &grpc.UnaryServerInfo{
var _Events_serviceDesc = grpc.ServiceDesc{
    Methods: []grpc.MethodDesc{
    Streams:  []grpc.StreamDesc{},

I'm running on bash v3.2.57 on macOS Sierra v10.12.3.

Very strange @dsnet , the only difference with you is :

  • I'm on OSX Mojave 10.14.1
  • My libprotoc verison is the last one 3.7.1

Another strange thing is my generated code contain :

const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package

and not

const _ = grpc.SupportPackageIsVersion4

Ok as far as I'm concerned the problem is solved: I just don't know how to
type "gRPC" correctly in a CLI, and needed 3 days to realize this.

By the way I'm on Linux and everything works fine, if this helps you
prioritize hypothesis.

Good luck

On Wed, Apr 3, 2019, 12:04 PM bastien notifications@github.com wrote:

Very strange @dsnet https://github.com/dsnet , the only difference with
you is :

  • I'm on OSX Mojave 10.14.1
  • My libprotoc verison is the last one 3.7.1

Another strange thing is my generated code contain :

const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package

and not

const _ = grpc.SupportPackageIsVersion4

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/golang/protobuf/issues/826#issuecomment-479424700,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYoS9AnvZYoQhVpNX2q1nLlKdL5hZRKwks5vdHyVgaJpZM4cFioz
.

Ho my... in my case not a "grpc" typo issue but :plugin vs :plugins
May be an update of func (g *Generator) CommandLineParameters(parameter string) in protobuf/protoc-gen-go/generator/generator.go to manage unknown word could help.

i removed protoc-gen-go installed with brew and i installed it through go get -u github.com/golang/protobuf/protoc-gen-go. now it works correctly

I can confirm this bug.

Same here for me

In my case, the problem was on my side. I was running --go_out=. instead of --go_out=plugins=grpc:..

There, now everybody on github knows I can't read the documentation. :cry:

I am doing protoc --go_out=plugins=grpc:. *.proto with protobuf 3.9.0 also I reinstalled with go get -u github.com/golang/protobuf/protoc-gen-go still it does not work. I am using this for years and has not happend to be.

I've installed protoc-gen-go with "go get -u github.com/golang/protobuf/protoc-gen-go", but it doesn't work when I run "protoc --go_out=. *.proto".

I replace it with "protoc --go_out=plugins=grpc:. *.proto" then it working

Indeed, without the plugins=grpc the code does not know how to generate any RPC services at all.

i removed protoc-gen-go installed with brew and i installed it through go get -u github.com/golang/protobuf/protoc-gen-go. now it works correctly

hi, @jney , maybe you don't need to remove the one installed with brew. The key point is running --go_out=plugins=grpc:. as @gun1x said above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonomacd picture jonomacd  Â·  3Comments

parkr picture parkr  Â·  5Comments

aaabhilash97 picture aaabhilash97  Â·  4Comments

sitano picture sitano  Â·  4Comments

junghoahnsc picture junghoahnsc  Â·  5Comments