Go protobuf packages collision

末鹿安然 提交于 2021-01-29 12:44:13

问题


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

syntax = "proto3";

package gen;

message EvtKeepAlive
{

   string SvcName   = 2;

}

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"
)

回答1:


The file is valid; see the comments from dsnet in response to 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.



来源:https://stackoverflow.com/questions/63772572/go-protobuf-packages-collision

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!