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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user