Go protobuf 包冲突

标签 go protocol-buffers

您好我正在尝试用 Go 语言生成简单的 protobuf 文件

syntax = "proto3";

package gen;

message EvtKeepAlive
{

   string SvcName   = 2;

}
在标题中,我看到该包使用了两种不同的 proto go 实现,一种来自 github.com 一个来自 google.golang.org .据我了解,后者取代了前者,那么这个文件生成是否有效?
// versions:
//  protoc-gen-go v1.25.0-devel
//  protoc        v3.13.0
// source: common.proto

package gen

import (
    proto "github.com/golang/protobuf/proto"
    protoreflect "google.golang.org/protobuf/reflect/protoreflect"
    protoimpl "google.golang.org/protobuf/runtime/protoimpl"
    reflect "reflect"
    sync "sync"
)

最佳答案

文件有效;请参阅 dsnet 对 this issue 的回复:

The only reason the newly generated .pb.go files depend on the deprecated proto package is to enforce a weak dependency on a sufficiently new version of the legacy package. This is necessary because not everyone is using Go modules such that the Go toolchain would enforce this dependency constraint. I wasn't fond of adding it, but I think it's probably necessary to keep at least for a few months.

关于Go protobuf 包冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63772572/

相关文章:

go - 访问字符串的原始字节

bash - 无法在终端中运行 Go Bin

testing - 处理模糊错误时如何保持良好的 Go 包测试覆盖率?

java - 使用 JPA 的 Protocol Buffer

c++ - 在某些静态库中打开整个程序优化会显着增加库的大小!

go - 如何区分关闭和过滤的远程端口

.htaccess - Heroku htaccess 基本身份验证上的 Golang 应用程序

java - protobuf 在 Windows 上安装失败

c++ - 在 DEBUG 模式下调整字节字段大小时发生访问冲突

java - 如何使用protocol buffers编译器为我的服务生成java接口(interface)而不是抽象类?