Skip to content

Commit e85f025

Browse files
tritonenoahdietz
authored andcommitted
chore(storage): remove adapters dependency (#6350)
The go-type-adapters package is used only minimally in storage, and nowhere else in google-cloud-go. Seems easiest to just drop this dependency.
1 parent dce734e commit e85f025

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

storage/bucket.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import (
2828
"cloud.google.com/go/internal/optional"
2929
"cloud.google.com/go/internal/trace"
3030
storagepb "cloud.google.com/go/storage/internal/apiv2/stubs"
31-
"github.com/googleapis/go-type-adapters/adapters"
3231
"google.golang.org/api/googleapi"
3332
"google.golang.org/api/iamcredentials/v1"
3433
"google.golang.org/api/iterator"
3534
"google.golang.org/api/option"
3635
raw "google.golang.org/api/storage/v1"
36+
dpb "google.golang.org/genproto/googleapis/type/date"
3737
"google.golang.org/protobuf/proto"
3838
)
3939

@@ -1613,13 +1613,13 @@ func toProtoLifecycle(l Lifecycle) *storagepb.Bucket_Lifecycle {
16131613
}
16141614

16151615
if !r.Condition.CreatedBefore.IsZero() {
1616-
rr.Condition.CreatedBefore = adapters.TimeToProtoDate(r.Condition.CreatedBefore)
1616+
rr.Condition.CreatedBefore = timeToProtoDate(r.Condition.CreatedBefore)
16171617
}
16181618
if !r.Condition.CustomTimeBefore.IsZero() {
1619-
rr.Condition.CustomTimeBefore = adapters.TimeToProtoDate(r.Condition.CustomTimeBefore)
1619+
rr.Condition.CustomTimeBefore = timeToProtoDate(r.Condition.CustomTimeBefore)
16201620
}
16211621
if !r.Condition.NoncurrentTimeBefore.IsZero() {
1622-
rr.Condition.NoncurrentTimeBefore = adapters.TimeToProtoDate(r.Condition.NoncurrentTimeBefore)
1622+
rr.Condition.NoncurrentTimeBefore = timeToProtoDate(r.Condition.NoncurrentTimeBefore)
16231623
}
16241624
rl.Rule = append(rl.Rule, rr)
16251625
}
@@ -1716,13 +1716,13 @@ func toLifecycleFromProto(rl *storagepb.Bucket_Lifecycle) Lifecycle {
17161716
}
17171717

17181718
if rr.GetCondition().GetCreatedBefore() != nil {
1719-
r.Condition.CreatedBefore = adapters.ProtoDateToUTCTime(rr.GetCondition().GetCreatedBefore())
1719+
r.Condition.CreatedBefore = protoDateToUTCTime(rr.GetCondition().GetCreatedBefore())
17201720
}
17211721
if rr.GetCondition().GetCustomTimeBefore() != nil {
1722-
r.Condition.CustomTimeBefore = adapters.ProtoDateToUTCTime(rr.GetCondition().GetCustomTimeBefore())
1722+
r.Condition.CustomTimeBefore = protoDateToUTCTime(rr.GetCondition().GetCustomTimeBefore())
17231723
}
17241724
if rr.GetCondition().GetNoncurrentTimeBefore() != nil {
1725-
r.Condition.NoncurrentTimeBefore = adapters.ProtoDateToUTCTime(rr.GetCondition().GetNoncurrentTimeBefore())
1725+
r.Condition.NoncurrentTimeBefore = protoDateToUTCTime(rr.GetCondition().GetNoncurrentTimeBefore())
17261726
}
17271727
l.Rules = append(l.Rules, r)
17281728
}
@@ -2236,3 +2236,28 @@ func (rpo RPO) String() string {
22362236
return rpoUnknown
22372237
}
22382238
}
2239+
2240+
// protoDateToUTCTime returns a new Time based on the google.type.Date, in UTC.
2241+
//
2242+
// Hours, minutes, seconds, and nanoseconds are set to 0.
2243+
func protoDateToUTCTime(d *dpb.Date) time.Time {
2244+
return protoDateToTime(d, time.UTC)
2245+
}
2246+
2247+
// protoDateToTime returns a new Time based on the google.type.Date and provided
2248+
// *time.Location.
2249+
//
2250+
// Hours, minutes, seconds, and nanoseconds are set to 0.
2251+
func protoDateToTime(d *dpb.Date, l *time.Location) time.Time {
2252+
return time.Date(int(d.GetYear()), time.Month(d.GetMonth()), int(d.GetDay()), 0, 0, 0, 0, l)
2253+
}
2254+
2255+
// timeToProtoDate returns a new google.type.Date based on the provided time.Time.
2256+
// The location is ignored, as is anything more precise than the day.
2257+
func timeToProtoDate(t time.Time) *dpb.Date {
2258+
return &dpb.Date{
2259+
Year: int32(t.Year()),
2260+
Month: int32(t.Month()),
2261+
Day: int32(t.Day()),
2262+
}
2263+
}

storage/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/google/go-cmp v0.5.8
1111
github.com/google/uuid v1.3.0
1212
github.com/googleapis/gax-go/v2 v2.4.0
13-
github.com/googleapis/go-type-adapters v1.0.0
1413
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2
1514
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f
1615
google.golang.org/api v0.85.0

storage/go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ github.com/googleapis/gax-go/v2 v2.2.0/go.mod h1:as02EH8zWkzwUoLbBaFeQ+arQaj/Oth
179179
github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99EXz9pXxye9YM=
180180
github.com/googleapis/gax-go/v2 v2.4.0 h1:dS9eYAjhrE2RjmzYw2XAPvcXfmcQLtFEQWn0CR82awk=
181181
github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c=
182-
github.com/googleapis/go-type-adapters v1.0.0 h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA=
183182
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
184183
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
185184
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=

0 commit comments

Comments
 (0)