去protobuf包碰撞 [英] Go protobuf packages collision

查看:62
本文介绍了去protobuf包碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I am trying to generate the simple protobuf file in Go language

syntax = "proto3";

package gen;

message EvtKeepAlive
{

   string SvcName   = 2;

}

在标题中,我看到该软件包使用了两种不同的proto go实现,一种来自 github.com ,另一种来自 google.golang.org .据我了解,后者取代了前者,那么这个文件生成有效吗?

In the header I see that the package uses two different proto go implementations, one from github.com and one from google.golang.org. As far as I understand the latter supersedes the former, so is this file generation valid?

// 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的评论,以回应此问题:

The file is valid; see the comments from dsnet in response to this issue:

新生成的.pb.go文件取决于不推荐使用的原始程序包是对一个程序执行弱依赖性旧版程序包的足够新的版本.这是必要的因为不是每个人都在使用Go模块,所以Go工具链将强制执行此依赖关系约束.我不喜欢添加它,但我认为可能至少要保留几个月.

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.

这篇关于去protobuf包碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆