Remove gogo/protobuf and adjust types

This commit migrates containerd/protobuf from github.com/gogo/protobuf
to google.golang.org/protobuf and adjust types. Proto-generated structs
cannot be passed as values.

Fixes #6564.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
Kazuyoshi Kato
2022-04-19 16:25:10 +00:00
parent fd37cc75be
commit e3db7de8f5
8 changed files with 44 additions and 53 deletions

View File

@@ -19,30 +19,18 @@ package protobuf
import (
"time"
"github.com/gogo/protobuf/types"
"google.golang.org/protobuf/types/known/timestamppb"
)
// Once we migrate off from gogo/protobuf, we can use the function below, which don't return any errors.
// https://github.com/protocolbuffers/protobuf-go/blob/v1.28.0/types/known/timestamppb/timestamp.pb.go#L200-L208
// ToTimestamp creates protobuf's Timestamp from time.Time.
func ToTimestamp(from time.Time) *types.Timestamp {
pt, err := types.TimestampProto(from)
if err != nil {
panic(err)
}
return pt
func ToTimestamp(from time.Time) *timestamppb.Timestamp {
return timestamppb.New(from)
}
// FromTimestamp creates time.Time from protobuf's Timestamp.
func FromTimestamp(from *types.Timestamp) time.Time {
if from == nil {
// Return time.Time's zero value as like timestamppb.
return time.Time{}.UTC()
}
tt, err := types.TimestampFromProto(from)
if err != nil {
panic(err)
}
return tt
func FromTimestamp(from *timestamppb.Timestamp) time.Time {
return from.AsTime()
}