设置事件通知
更新时间: 2019-03-14 10:05
您可以通过ObsClient.SetBucketNotification设置桶的事件通知。以下代码展示了如何设置桶的事件通知:
- var ak = "*** Provide your Access Key ***"
- var sk = "*** Provide your Secret Key ***"
- var endpoint = "https://your-endpoint"
- // 创建ObsClient结构体
- var obsClient, _ = obs.New(ak, sk, endpoint)
- func main() {
- input := &obs.SetBucketNotificationInput{}
- input.Bucket = "bucketname"
- var topicConfigurations [1]obs.TopicConfiguration
- topicConfigurations[0] = obs.TopicConfiguration{}
- topicConfigurations[0].ID = "001"
- topicConfigurations[0].Topic = "topic"
- topicConfigurations[0].Events = []obs.EventType{obs.ObjectCreateAll}
- var filterRules [2]obs.FilterRule
- filterRules[0] = obs.FilterRule{Name: "prefix", Value: "smn"}
- filterRules[1] = obs.FilterRule{Name: "suffix", Value: ".jpg"}
- topicConfigurations[0].FilterRules = filterRules[:]
- input.TopicConfigurations = topicConfigurations[:]
- output, err := obsClient.SetBucketNotification(input)
- if err == nil {
- fmt.Printf("RequestId:%s\n", output.RequestId)
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
父主题:事件通知