@@ -21,6 +21,7 @@ import (
21
21
"time"
22
22
23
23
pb "google.golang.org/genproto/googleapis/pubsub/v1"
24
+ fmpb "google.golang.org/genproto/protobuf/field_mask"
24
25
"google.golang.org/protobuf/types/known/timestamppb"
25
26
)
26
27
@@ -42,11 +43,30 @@ func (s *Snapshot) ID() string {
42
43
return s .name [slash + 1 :]
43
44
}
44
45
46
+ // SetLabels sets or replaces the labels on a given snapshot.
47
+ func (s * Snapshot ) SetLabels (ctx context.Context , label map [string ]string ) (* SnapshotConfig , error ) {
48
+ sc , err := s .c .subc .UpdateSnapshot (ctx , & pb.UpdateSnapshotRequest {
49
+ Snapshot : & pb.Snapshot {
50
+ Name : s .name ,
51
+ Labels : label ,
52
+ },
53
+ UpdateMask : & fmpb.FieldMask {
54
+ Paths : []string {"labels" },
55
+ },
56
+ })
57
+ if err != nil {
58
+ return nil , err
59
+ }
60
+ return toSnapshotConfig (sc , s .c )
61
+ }
62
+
45
63
// SnapshotConfig contains the details of a Snapshot.
46
64
type SnapshotConfig struct {
47
65
* Snapshot
48
66
Topic * Topic
49
67
Expiration time.Time
68
+ // The set of labels for the snapshot.
69
+ Labels map [string ]string
50
70
}
51
71
52
72
// Snapshot creates a reference to a snapshot.
@@ -151,5 +171,6 @@ func toSnapshotConfig(snap *pb.Snapshot, c *Client) (*SnapshotConfig, error) {
151
171
Snapshot : & Snapshot {c : c , name : snap .Name },
152
172
Topic : newTopic (c , snap .Topic ),
153
173
Expiration : exp ,
174
+ Labels : snap .Labels ,
154
175
}, nil
155
176
}
0 commit comments