查看托管配置

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

您可以通过ObsClient.GetBucketWebsiteConfiguration查看桶的托管配置。以下代码展示了如何查看托管配置:

  1. // 引入依赖包
  2. import (
  3. "fmt"
  4. "obs"
  5. )
  6.  
  7. var ak = "*** Provide your Access Key ***"
  8. var sk = "*** Provide your Secret Key ***"
  9. var endpoint = "https://your-endpoint"
  10.  
  11. // 创建ObsClient结构体
  12. var obsClient, _ = obs.New(ak, sk, endpoint)
  13.  
  14. func main() {
  15. output, err := obsClient.GetBucketWebsiteConfiguration("bucketname")
  16. if err == nil {
  17. fmt.Printf("RedirectAllRequestsTo.HostName:%s,RedirectAllRequestsTo.Protocol:%s\n", output.RedirectAllRequestsTo.HostName, output.RedirectAllRequestsTo.Protocol)
  18. fmt.Printf("Suffix:%s\n", output.IndexDocument.Suffix)
  19. fmt.Printf("Key:%s\n", output.ErrorDocument.Key)
  20. for index, routingRule := range output.RoutingRules {
  21. fmt.Printf("Condition[%d]-KeyPrefixEquals:%s, HttpErrorCodeReturnedEquals:%s\n", index, routingRule.Condition.KeyPrefixEquals, routingRule.Condition.HttpErrorCodeReturnedEquals)
  22. fmt.Printf("Redirect[%d]-Protocol:%s, HostName:%s, ReplaceKeyPrefixWith:%s, HttpRedirectCode:%s\n",
  23. index, routingRule.Redirect.Protocol, routingRule.Redirect.HostName, routingRule.Redirect.ReplaceKeyPrefixWith, routingRule.Redirect.HttpRedirectCode)
  24. }
  25. } else if obsError, ok := err.(obs.ObsError); ok {
  26. fmt.Printf("Code:%s\n", obsError.Code)
  27. fmt.Printf("Message:%s\n", obsError.Message)
  28. }
  29. }

父主题:静态网站托管