设置事件通知

更新时间: 2019-03-14 10:05

您可以通过ObsClient.SetBucketNotification设置桶的事件通知。以下代码展示了如何设置桶的事件通知:

  1. var ak = "*** Provide your Access Key ***"
  2. var sk = "*** Provide your Secret Key ***"
  3. var endpoint = "https://your-endpoint"
  4.  
  5. // 创建ObsClient结构体
  6. var obsClient, _ = obs.New(ak, sk, endpoint)
  7.  
  8. func main() {
  9. input := &obs.SetBucketNotificationInput{}
  10. input.Bucket = "bucketname"
  11. var topicConfigurations [1]obs.TopicConfiguration
  12. topicConfigurations[0] = obs.TopicConfiguration{}
  13. topicConfigurations[0].ID = "001"
  14. topicConfigurations[0].Topic = "topic"
  15. topicConfigurations[0].Events = []obs.EventType{obs.ObjectCreateAll}
  16.  
  17. var filterRules [2]obs.FilterRule
  18.  
  19. filterRules[0] = obs.FilterRule{Name: "prefix", Value: "smn"}
  20. filterRules[1] = obs.FilterRule{Name: "suffix", Value: ".jpg"}
  21. topicConfigurations[0].FilterRules = filterRules[:]
  22.  
  23. input.TopicConfigurations = topicConfigurations[:]
  24. output, err := obsClient.SetBucketNotification(input)
  25. if err == nil {
  26. fmt.Printf("RequestId:%s\n", output.RequestId)
  27. } else if obsError, ok := err.(obs.ObsError); ok {
  28. fmt.Printf("Code:%s\n", obsError.Code)
  29. fmt.Printf("Message:%s\n", obsError.Message)
  30. }
  31. }

父主题:事件通知