Protoc无服务创建
来源:stackoverflow
时间:2024-02-24 13:06:27 259浏览 收藏
来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习Golang相关编程知识。下面本篇文章就来带大家聊聊《Protoc无服务创建》,介绍一下,希望对大家的知识积累有所帮助,助力实战开发!
问题内容
我只是想使用协议缓冲区为 golang 生成代码。但无法使用protoc命令生成服务。
syntax = "proto3"; package greet; option go_package="./greet/greetpb"; service greetservice{}
上面是一个虚拟的原始文件,我正在尝试将其转换为 golang。但无法生成正确的文件,因为在我的系统中它无法将 service greetservice{}
行识别为服务。
我在windows系统上使用以下版本的protoc:
ps d:\study\grpc\go-grpc-course> protoc --version libprotoc 3.17.3
使用以下命令生成代码:
协议 .\greet\greetpb\greet.proto --go_out=.
下面是上面命令生成的go代码:
// 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代码中没有创建任何服务。我做错了什么还是这是一些原始问题。如有任何帮助,我们将不胜感激。
正确答案
在使用 protoc
时,您似乎忘记添加 go-grpc_out
参数。该参数用于生成 grpc 代码。请尝试以下操作:
protoc greet.proto --go_out=. --go-grpc_out=.
这在the gRPC quickstart - section "Regenerate gRPC code"中也有描述
终于介绍完啦!小伙伴们,这篇关于《Protoc无服务创建》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!
声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
最新阅读
更多>
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习