Source File
notifications.go
Belonging Package
cloud.google.com/go/storage
package storage
import (
raw
)
NoPayload = "NONE"
JSONPayload = "JSON_API_V1"
)
ObjectFinalizeEvent = "OBJECT_FINALIZE"
ObjectMetadataUpdateEvent = "OBJECT_METADATA_UPDATE"
ObjectDeleteEvent = "OBJECT_DELETE"
ObjectArchiveEvent = "OBJECT_ARCHIVE"
)
func ( *raw.Notification) *Notification {
:= &Notification{
ID: .Id,
EventTypes: .EventTypes,
ObjectNamePrefix: .ObjectNamePrefix,
CustomAttributes: .CustomAttributes,
PayloadFormat: .PayloadFormat,
}
.TopicProjectID, .TopicID = parseNotificationTopic(.Topic)
return
}
var topicRE = regexp.MustCompile("^//pubsub.googleapis.com/projects/([^/]+)/topics/([^/]+)")
func ( string) (, string) {
:= topicRE.FindStringSubmatch()
if == nil {
return "?", "?"
}
return [1], [2]
}
func ( *Notification) *raw.Notification {
return &raw.Notification{
Id: .ID,
Topic: fmt.Sprintf("//pubsub.googleapis.com/projects/%s/topics/%s",
.TopicProjectID, .TopicID),
EventTypes: .EventTypes,
ObjectNamePrefix: .ObjectNamePrefix,
CustomAttributes: .CustomAttributes,
PayloadFormat: string(.PayloadFormat),
}
}
func ( *BucketHandle) ( context.Context, *Notification) ( *Notification, error) {
= trace.StartSpan(, "cloud.google.com/go/storage.Bucket.AddNotification")
defer func() { trace.EndSpan(, ) }()
if .ID != "" {
return nil, errors.New("storage: AddNotification: ID must not be set")
}
if .TopicProjectID == "" {
return nil, errors.New("storage: AddNotification: missing TopicProjectID")
}
if .TopicID == "" {
return nil, errors.New("storage: AddNotification: missing TopicID")
}
:= .c.raw.Notifications.Insert(.name, toRawNotification())
setClientHeader(.Header())
if .userProject != "" {
.UserProject(.userProject)
}
, := .Context().Do()
if != nil {
return nil,
}
return toNotification(), nil
}
func ( *BucketHandle) ( context.Context) ( map[string]*Notification, error) {
= trace.StartSpan(, "cloud.google.com/go/storage.Bucket.Notifications")
defer func() { trace.EndSpan(, ) }()
:= .c.raw.Notifications.List(.name)
setClientHeader(.Header())
if .userProject != "" {
.UserProject(.userProject)
}
var *raw.Notifications
= runWithRetry(, func() error {
, = .Context().Do()
return
})
if != nil {
return nil,
}
return notificationsToMap(.Items), nil
}
func ( []*raw.Notification) map[string]*Notification {
:= map[string]*Notification{}
for , := range {
[.Id] = toNotification()
}
return
}
func ( *BucketHandle) ( context.Context, string) ( error) {
= trace.StartSpan(, "cloud.google.com/go/storage.Bucket.DeleteNotification")
defer func() { trace.EndSpan(, ) }()
:= .c.raw.Notifications.Delete(.name, )
setClientHeader(.Header())
if .userProject != "" {
.UserProject(.userProject)
}
return .Context().Do()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |