I am just trying to generate code for golang using protocol buffer. But unable to generate the service using protoc command.
syntax = "proto3";
package greet;
option go_package="./greet/greetpb";
service GreetService{}
Above is a dummy proto file that I am trying to convert into golang. But unable to generate the correct file as in my system it doesn't recognize service GreetService{}
line as a service.
I am using the following version of protoc on windows system:
PS D:\Study\grpc\go-grpc-course> protoc --version
libprotoc 3.17.3
Using below command to generate the code:
protoc .\greet\greetpb\greet.proto --go_out=.
Below is the go code generated by above command:
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.3
// source: greet/greetpb/greet.proto
package greetpb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
var File_greet_greetpb_greet_proto protoreflect.FileDescriptor
var file_greet_greetpb_greet_proto_rawDesc = []byte{
0x0a, 0x19, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2f, 0x67, 0x72, 0x65, 0x65, 0x74, 0x70, 0x62, 0x2f,
0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67, 0x72, 0x65,
0x65, 0x74, 0x32, 0x0e, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x42, 0x11, 0x5a, 0x0f, 0x2e, 0x2f, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2f, 0x67, 0x72,
0x65, 0x65, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var file_greet_greetpb_greet_proto_goTypes = []interface{}{}
var file_greet_greetpb_greet_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_greet_greetpb_greet_proto_init() }
func file_greet_greetpb_greet_proto_init() {
if File_greet_greetpb_greet_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_greet_greetpb_greet_proto_rawDesc,
NumEnums: 0,
NumMessages: 0,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_greet_greetpb_greet_proto_goTypes,
DependencyIndexes: file_greet_greetpb_greet_proto_depIdxs,
}.Build()
File_greet_greetpb_greet_proto = out.File
file_greet_greetpb_greet_proto_rawDesc = nil
file_greet_greetpb_greet_proto_goTypes = nil
file_greet_greetpb_greet_proto_depIdxs = nil
}
There aren't any services created in the later go code. Am I doing something wrong or is this some proto issue. Any help is appreciated.
You seem to forgot to add the go-grpc_out
argument when using protoc
. This argument is for generating the gRPC code. Please try the following:
protoc greet.proto --go_out=. --go-grpc_out=.
This is also described in the gRPC quickstart - section "Regenerate gRPC code"