首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Protoc不创建服务

Protoc不创建服务
EN

Stack Overflow用户
提问于 2021-06-22 05:42:09
回答 1查看 756关注 0票数 4

我只是尝试使用协议缓冲区为golang生成代码。但是无法使用protoc命令生成服务。

代码语言:javascript
运行
复制
syntax = "proto3";
package greet;
option go_package="./greet/greetpb";
service GreetService{}

上面是一个虚拟的proto文件,我正试图将它转换为golang。但是无法生成正确的文件,就像在我的系统中一样,它不承认service GreetService{}行是一个服务。

我在windows系统上使用以下版本的protoc:

代码语言:javascript
运行
复制
PS D:\Study\grpc\go-grpc-course> protoc --version
libprotoc 3.17.3

使用下面的命令生成代码:

原语.\greet\greetpb\greet.proto -外出=。

下面是上述命令生成的go代码:

代码语言:javascript
运行
复制
// 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
}

在后面的go代码中没有创建任何服务。我是做错什么了还是这是什么问题。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-22 09:23:59

在使用go-grpc_out时,您似乎忘了添加protoc参数。此参数用于生成gRPC代码。请试用以下方法:

代码语言:javascript
运行
复制
protoc greet.proto --go_out=. --go-grpc_out=.

这在gRPC快速启动部分“重新生成gRPC代码”中也有描述。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68078115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档