在使用 protoc 工具生成 go 代码的时候报出的如下错误:
在syntax = “proto3”; //版本号版本中字段默认为syntax = “proto3”; //版本号

protoc ./test.proto --go_out=./WARNING: Missing 'go_package' option in "message.proto",
please specify it with the full Go package path as
a future release of protoc-gen-go will require this be specified.

是因为在 proto3 的语法中缺少了 option go_package。
解决:
在syntax下面添加option信息

option go_package = "student;student";
student 表示生成的go文件的存放地址,会自动生成目录的。
stu表示生成的go文件所属的包名

比如:

option go_package = "student;stu";

test.proto


syntax = "proto3"; //版本号
option go_package = "student;stu";
message Student{ //消息,对应于Go的结构体string name=1; //1:标号,唯一 即可(相当于数据库中的Id,不一定要从1 ,2的顺序依次排列。)int32 age=2;  //必须指定整型的范围,如int32,int64string address=3;ClassName cn=4;
}
message Students{repeated Student person=1;  // repeated 修饰,相当于Go中切片string school=2;
}
enum ClassName{   //枚举class1=0;  //标号 必须从 0开始class2=1;class3=2;
}

proto_test为我工程的目录

最后生成的结构如上
test.pb.go

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
//  protoc-gen-go v1.25.0-devel
//  protoc        (unknown)
// source: test.protopackage stuimport (protoreflect "google.golang.org/protobuf/reflect/protoreflect"protoimpl "google.golang.org/protobuf/runtime/protoimpl"reflect "reflect"sync "sync"
)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)
)type ClassName int32const (ClassName_class1 ClassName = 0 //标号 必须从 0开始ClassName_class2 ClassName = 1ClassName_class3 ClassName = 2
)// Enum value maps for ClassName.
var (ClassName_name = map[int32]string{0: "class1",1: "class2",2: "class3",}ClassName_value = map[string]int32{"class1": 0,"class2": 1,"class3": 2,}
)func (x ClassName) Enum() *ClassName {p := new(ClassName)*p = xreturn p
}func (x ClassName) String() string {return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}func (ClassName) Descriptor() protoreflect.EnumDescriptor {return file_test_proto_enumTypes[0].Descriptor()
}func (ClassName) Type() protoreflect.EnumType {return &file_test_proto_enumTypes[0]
}func (x ClassName) Number() protoreflect.EnumNumber {return protoreflect.EnumNumber(x)
}// Deprecated: Use ClassName.Descriptor instead.
func (ClassName) EnumDescriptor() ([]byte, []int) {return file_test_proto_rawDescGZIP(), []int{0}
}type Student struct {state         protoimpl.MessageStatesizeCache     protoimpl.SizeCacheunknownFields protoimpl.UnknownFieldsName    string    `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` //1:标号,唯一 即可(相当于数据库中的Id,不一定要从1 ,2的顺序依次排列。)Age     int32     `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"`  //必须指定整型的范围,如int32,int64Address string    `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`Cn      ClassName `protobuf:"varint,4,opt,name=cn,proto3,enum=ClassName" json:"cn,omitempty"`
}func (x *Student) Reset() {*x = Student{}if protoimpl.UnsafeEnabled {mi := &file_test_proto_msgTypes[0]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}
}func (x *Student) String() string {return protoimpl.X.MessageStringOf(x)
}func (*Student) ProtoMessage() {}func (x *Student) ProtoReflect() protoreflect.Message {mi := &file_test_proto_msgTypes[0]if protoimpl.UnsafeEnabled && x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {ms.StoreMessageInfo(mi)}return ms}return mi.MessageOf(x)
}// Deprecated: Use Student.ProtoReflect.Descriptor instead.
func (*Student) Descriptor() ([]byte, []int) {return file_test_proto_rawDescGZIP(), []int{0}
}func (x *Student) GetName() string {if x != nil {return x.Name}return ""
}func (x *Student) GetAge() int32 {if x != nil {return x.Age}return 0
}func (x *Student) GetAddress() string {if x != nil {return x.Address}return ""
}func (x *Student) GetCn() ClassName {if x != nil {return x.Cn}return ClassName_class1
}type Students struct {state         protoimpl.MessageStatesizeCache     protoimpl.SizeCacheunknownFields protoimpl.UnknownFieldsPerson []*Student `protobuf:"bytes,1,rep,name=person,proto3" json:"person,omitempty"` // repeated 修饰,相当于Go中切片School string     `protobuf:"bytes,2,opt,name=school,proto3" json:"school,omitempty"`
}func (x *Students) Reset() {*x = Students{}if protoimpl.UnsafeEnabled {mi := &file_test_proto_msgTypes[1]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}
}func (x *Students) String() string {return protoimpl.X.MessageStringOf(x)
}func (*Students) ProtoMessage() {}func (x *Students) ProtoReflect() protoreflect.Message {mi := &file_test_proto_msgTypes[1]if protoimpl.UnsafeEnabled && x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {ms.StoreMessageInfo(mi)}return ms}return mi.MessageOf(x)
}// Deprecated: Use Students.ProtoReflect.Descriptor instead.
func (*Students) Descriptor() ([]byte, []int) {return file_test_proto_rawDescGZIP(), []int{1}
}func (x *Students) GetPerson() []*Student {if x != nil {return x.Person}return nil
}func (x *Students) GetSchool() string {if x != nil {return x.School}return ""
}var File_test_proto protoreflect.FileDescriptorvar file_test_proto_rawDesc = []byte{0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x65, 0x0a, 0x07,0x53, 0x74, 0x75, 0x64, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61,0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a,0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1a, 0x0a, 0x02, 0x63, 0x6e, 0x18, 0x04, 0x20,0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x52,0x02, 0x63, 0x6e, 0x22, 0x44, 0x0a, 0x08, 0x53, 0x74, 0x75, 0x64, 0x65, 0x6e, 0x74, 0x73, 0x12,0x20, 0x0a, 0x06, 0x70, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32,0x08, 0x2e, 0x53, 0x74, 0x75, 0x64, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x70, 0x65, 0x72, 0x73, 0x6f,0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x6f, 0x6f, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28,0x09, 0x52, 0x06, 0x73, 0x63, 0x68, 0x6f, 0x6f, 0x6c, 0x2a, 0x2f, 0x0a, 0x09, 0x43, 0x6c, 0x61,0x73, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x31,0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x32, 0x10, 0x01, 0x12, 0x0a,0x0a, 0x06, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x33, 0x10, 0x02, 0x42, 0x0d, 0x5a, 0x0b, 0x73, 0x74,0x75, 0x64, 0x65, 0x6e, 0x74, 0x3b, 0x73, 0x74, 0x75, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,0x33,
}var (file_test_proto_rawDescOnce sync.Oncefile_test_proto_rawDescData = file_test_proto_rawDesc
)func file_test_proto_rawDescGZIP() []byte {file_test_proto_rawDescOnce.Do(func() {file_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_proto_rawDescData)})return file_test_proto_rawDescData
}var file_test_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_test_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_test_proto_goTypes = []interface{}{(ClassName)(0),   // 0: ClassName(*Student)(nil),  // 1: Student(*Students)(nil), // 2: Students
}
var file_test_proto_depIdxs = []int32{0, // 0: Student.cn:type_name -> ClassName1, // 1: Students.person:type_name -> Student2, // [2:2] is the sub-list for method output_type2, // [2:2] is the sub-list for method input_type2, // [2:2] is the sub-list for extension type_name2, // [2:2] is the sub-list for extension extendee0, // [0:2] is the sub-list for field type_name
}func init() { file_test_proto_init() }
func file_test_proto_init() {if File_test_proto != nil {return}if !protoimpl.UnsafeEnabled {file_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {switch v := v.(*Student); i {case 0:return &v.statecase 1:return &v.sizeCachecase 2:return &v.unknownFieldsdefault:return nil}}file_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {switch v := v.(*Students); i {case 0:return &v.statecase 1:return &v.sizeCachecase 2:return &v.unknownFieldsdefault:return nil}}}type x struct{}out := protoimpl.TypeBuilder{File: protoimpl.DescBuilder{GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: file_test_proto_rawDesc,NumEnums:      1,NumMessages:   2,NumExtensions: 0,NumServices:   0,},GoTypes:           file_test_proto_goTypes,DependencyIndexes: file_test_proto_depIdxs,EnumInfos:         file_test_proto_enumTypes,MessageInfos:      file_test_proto_msgTypes,}.Build()File_test_proto = out.Filefile_test_proto_rawDesc = nilfile_test_proto_goTypes = nilfile_test_proto_depIdxs = nil
}

2.遇到的问题

ubuntu@VM-0-17-ubuntu:~/go/testpb$ go build
testpb.go:7:2: unknown import path "/home/ubuntu/go/testpb/testpb.go": internal error: module loader did not resolve import
testpb.go:6:2: no required module provides package github.com/golang/protobuf/proto; to add it:go get github.com/golang/protobuf/proto
ubuntu@VM-0-17-ubuntu:~/go/testpb$ go get github.com/golang/protobuf/proto
go get: module github.com/golang/protobuf/proto: Get "https://proxy.golang.org/github.com/golang/protobuf/proto/@v/list": dial tcp 172.217.160.81:443: i/o timeout
ubuntu@VM-0-17-ubuntu:~/go/testpb$
ubuntu@VM-0-17-ubuntu:~/go/testpb$ go env -w GOPROXY=https://goproxy.cn
ubuntu@VM-0-17-ubuntu:~/go/testpb$ go get github.com/golang/protobuf/proto
go: downloading github.com/golang/protobuf v1.5.2
go: downloading google.golang.org/protobuf v1.26.0
go get: added github.com/golang/protobuf v1.5.2

go -生成pb文件 - 上相关推荐

  1. 【tensorflow】生成.pb文件

    Saving, Freezing, Optimizing for inference, Restoring of tensorflow models 在训练完tensorflow模型后,会有三个文件: ...

  2. mac golang grpc proto pb文件生成go文件.md

    文章目录 1.简介 2.操作步骤 1. 安装基础的protoc工具 1. 下载 2. 添加protoc到PATH 3. 安装golang的支持 4. 使用 1. 普通编译 2. import的路径 参 ...

  3. Slim生成的ckpt文件转PB文件

    前言 搭建Slim框架方法请参考这篇文章:搭建迁移训练Slim框架环境_17岁boy的博客-CSDN博客 生成PB文件 转换的方式也很简单,Slim自带了一个graph.py文件,文件存在于model ...

  4. TensorFlow:将ckpt文件固化成pb文件

    TensorFlow:将ckpt文件固化成pb文件 本文是将yolo3目标检测框架训练出来的ckpt文件固化成pb文件,主要利用了GitHub上的该项目. 为什么要最终生成pb文件呢?简单来说就是直接 ...

  5. 深度学习(六)——CNN识别典型地标建筑,并制作pb文件,部署在android studio端,制作app实现该功能

    一.背景 两年前的一个项目,识别典型地标,并对图片进行标记.这里只写一下简单思路,最开始是打算用特征点匹配来做的,可以参考:基于特征点匹配方法--SIFT, SURF, ORB的图像识别 ,后来发现效 ...

  6. java文件上传_Java文件上传细讲

    什么是文件上传? 文件上传就是把用户的信息保存起来. 为什么需要文件上传? 在用户注册的时候,可能需要用户提交照片.那么这张照片就应该要进行保存. 上传组件(工具) 为什么我们要使用上传工具? 为啥我 ...

  7. 【Android 安全】DEX 加密 ( Java 工具开发 | 生成 dex 文件 | Java 命令行执行 )

    文章目录 一.生成 dex 文件 二.生成 dex 文件代码示例 三.生成 dex 结果 参考博客 : [Android 安全]DEX 加密 ( 常用 Android 反编译工具 | apktool ...

  8. SpringBoot集成FastDFS依赖实现文件上传

    前言 对FastDFS文件系统安装后的使用. FastDFS的安装请参考这篇:https://www.cnblogs.com/niceyoo/p/13511082.html 本文环境:IDEA + J ...

  9. .net fileupload批量上传可删除_【JavaWeb基础】文件上传和下载(修订版)

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 什么是文件上传? 文件上传就是把用户的信息保存起来. ...

  10. Java文件上传细讲,大厂 HR 如何面试

    写在最前面,我总结出了很多互联网公司的面试题及答案,并整理成了文档,以及各种学习的进阶学习资料,免费分享给大家.扫码加微信好友进[程序员面试学习交流群],免费领取.也欢迎各位一起在群里探讨技术. 什么 ...

最新文章

  1. 操作系统的进程调度简析
  2. 登陆SharePoint站点出现service unavailable----Http错误503
  3. 从基于Maven的Web应用程序获取版本字符串
  4. ORACLE 进入sqlplus的协议适配器错误
  5. cpu,内存和disk使用报警脚本
  6. iis服务器文件上传大小限制,windows服务器中iis限制文件大小方法
  7. 百度文本编辑器ueditor v1.2.3.0使用方法及配置(图片上传功能、目录更改)
  8. Ideal配置Struts项目提示Cannot resolve symbol 'xx.jsp',以及没有找到Namespace为/的指定Action的解决
  9. 阶段3 2.Spring_03.Spring的 IOC 和 DI_11 set方法注入
  10. 职高计算机专业小白可以读吗,「高考从小白到精通」报考计算机类专业是否是一个正确的选择?...
  11. 四款优秀的源代码扫描工具简介
  12. MySQL学习 --- 嵌套查询
  13. 修改Linux文件格式为unix
  14. 【RX解码MIPI输出】XS9922B 4通道模拟复合视频解码芯片 功能对标TP2815
  15. [笔记] 数据结构二刷【第一篇:线性表·栈·队列·递归】
  16. python批量下载模库网图片
  17. MATLAB怎么计算曲面面积,Matlab曲面面积估计.doc
  18. macbook pro的漏电
  19. esp32语音控制_乐鑫发布针对物联网嵌入式设备AI语音麦克风阵列开发板
  20. 二项分布的期望和方差

热门文章

  1. Android——控件显示和隐藏
  2. css3图片 变黑白 变模糊 调整饱和度等
  3. Xcode之断点调试
  4. #VSTS日志# Xamarin构建支持和一大波更新
  5. java文件下载和导出文件名乱码浏览器兼容性问题
  6. 【工具】JAVA 在单元读取文件并比较
  7. jquery中checkbox全选失效的解决方法
  8. 面试题-JQuery里Ajax的原理是怎样的?
  9. 推荐一款ORM工具 FOR ADOBE AIR
  10. Kubernetes详解(九)——资源配置清单创建Pod实战