查看跨域规则

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

您可以通过ObsClient.GetBucketCors查看桶的跨域规则。以下代码展示了如何查看跨域规则:

  1. // 引入依赖包
  2. import (
  3. "fmt"
  4. "obs"
  5. "strings"
  6. )
  7.  
  8. var ak = "*** Provide your Access Key ***"
  9. var sk = "*** Provide your Secret Key ***"
  10. var endpoint = "https://your-endpoint"
  11.  
  12. // 创建ObsClient结构体
  13. var obsClient, _ = obs.New(ak, sk, endpoint)
  14.  
  15. func main() {
  16. output, err := obsClient.GetBucketCors("bucketname")
  17. if err == nil {
  18. for _, corsRule := range output.CorsRules {
  19. fmt.Printf("ID:%s, AllowedOrigin:%s, AllowedMethod:%s, AllowedHeader:%s, MaxAgeSeconds:%d, ExposeHeader:%s\n",
  20. corsRule.ID, strings.Join(corsRule.AllowedOrigin, "|"), strings.Join(corsRule.AllowedMethod, "|"),
  21. strings.Join(corsRule.AllowedHeader, "|"), corsRule.MaxAgeSeconds, strings.Join(corsRule.ExposeHeader, "|"))
  22. }
  23. } else if obsError, ok := err.(obs.ObsError); ok {
  24. fmt.Printf("Code:%s\n", obsError.Code)
  25. fmt.Printf("Message:%s\n", obsError.Message)
  26. }
  27. }

父主题:跨域资源共享