Go protobuf 包冲突
Go protobuf packages collision
您好,我正在尝试用 Go 语言生成简单的 protobuf 文件
syntax = "proto3";
package gen;
message EvtKeepAlive
{
string SvcName = 2;
}
在 header 中,我看到该包使用了两种不同的 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 文件
syntax = "proto3";
package gen;
message EvtKeepAlive
{
string SvcName = 2;
}
在 header 中,我看到该包使用了两种不同的 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.