Updated on 2022-02-10 GMT+08:00

GET Bucket cors

API Description

You can use this API to obtain the CORS rules of a specified bucket.

Method Definition

func (obsClient ObsClient) GetBucketCors(bucketName string) (output *GetBucketCorsOutput, err error)

Method Definition If a Signed URL Is Used

func (obsClient ObsClient) GetBucketCorsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketCorsOutput, err error)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

string

Mandatory

Bucket name

Returned Result

Field

Type

output

*GetBucketCorsOutput

err

error

Sample Code

func main() {
       output, err := obsClient.GetBucketCors("bucketname")
       if err == nil {
              fmt.Printf("RequestId:%s\n", output.RequestId)
              for _, corsRule := range output.CorsRules {
                     fmt.Printf("ID:%s, AllowedOrigin:%s, AllowedMethod:%s, AllowedHeader:%s, MaxAgeSeconds:%d, ExposeHeader:%s\n",
                           corsRule.ID, strings.Join(corsRule.AllowedOrigin, "|"), strings.Join(corsRule.AllowedMethod, "|"),
                           strings.Join(corsRule.AllowedHeader, "|"), corsRule.MaxAgeSeconds, strings.Join(corsRule.ExposeHeader, "|"))
              }
       } else {
              if obsError, ok := err.(obs.ObsError); ok {
                     fmt.Println(obsError.Code)
                     fmt.Println(obsError.Message)
              } else {
                     fmt.Println(err)
              }
       }
}