Static Website

Last updated: 2020-03-20 11:01:12

PDF

Note

This document provides an overview of API on static websites and sample SDK code.

API Operation name pedagogical operation
PUT Bucket website Setting up a Static Website Set Bucket's static website configuration
GET Bucket website Query static site configuration Query Bucket's static website configuration
DELETE Bucket website Delete static site configuration Delete Bucket's static website configuration

Setting up a Static Website

Function description

PUT Bucket website is used to configure a static website for Bucket.

Method prototype

func (s *BucketService) PutWebsite(ctx context.Context, opt *BucketPutWebsiteOptions) (*Response, error)

Request Sample

opt := &cos.BucketPutWebsiteOptions{
    Index: "index.html",
    Error: &cos.ErrorDocument{"index_backup.html"},
    RoutingRules: &cos.WebsiteRoutingRules{
        []cos.WebsiteRoutingRule{
        {   
            ConditionErrorCode: "404",
            RedirectProtocol:   "https",
            RedirectReplaceKey: "404.html",
        },  
        {   
            ConditionPrefix:          "docs/",
            RedirectProtocol:         "https",
            RedirectReplaceKeyPrefix: "documents/",
        },  
        },  
    },  
}   
resp, err := client.Bucket.PutWebsite(context.Background(), opt)

Parameter description

type WebsiteRoutingRule struct {
    ConditionErrorCode string 
    ConditionPrefix    string 

    RedirectProtocol         string 
    RedirectReplaceKey       string 
    RedirectReplaceKeyPrefix string 
}

type WebsiteRoutingRules struct {
    Rules []WebsiteRoutingRule
}

type ErrorDocument struct {
    Key string 
}

type RedirectRequestsProtocol struct {
    Protocol string 
}

type BucketPutWebsiteOptions struct {
    XMLName          xml.Name                  
    Index            string                    
    RedirectProtocol *RedirectRequestsProtocol
    Error            *ErrorDocument            
    RoutingRules     *WebsiteRoutingRules
}
Parameter name Description Type
BucketPutWebsiteOptions Static website configuration parameters Struct
INDEX Specify an indexed document String
RedirectProtocol Protocol, who is redirected at the whole station. Struct
Protocol Protocol who specifies the site-wide redirection can only be set to https String
Error Error document Struct
Key Specify generic error return String
RoutingRules Set redirection rules. Set a maximum of 100 RoutingRule Struct
ConditionErrorCode Specify redirect error code. Only 4XX error code can be configured. Priority is higher than Error.Key. String
ConditionPrefix Specifies the path to the prefix redirection, replacing the specified folder/ String
RedirectProtocol Protocol, which specifies the redirection, can only be set to https. String
RedirectReplaceKey Replace the entire Key with the specified content String
RedirectReplaceKeyPrefix Replace the prefix that matches to the specified content, and the Conditon can only be set to KeyPrefixEquals. String

Query static site configuration

Function description

GET Bucket website is used to query static website configuration information with Bucket and Associate.

Method prototype

func (s *BucketService) GetWebsite(ctx context.Context) (*BucketGetWebsiteResult, *Response, error)

Request Sample

res, rsp, err := client.Bucket.GetWebsite(context.Background())

Return result description

type BucketGetWebsiteResult BucketPutWebsiteOptions
Parameter name Description Type
BucketGetWebsiteResult Static website configuration parameters Struct
INDEX Specify an indexed document String
RedirectProtocol Protocol, who is redirected at the whole station. Struct
Protocol Protocol who specifies the site-wide redirection can only be set to https String
Error General error return Struct
Key Specify generic error return String
RoutingRules Set redirection rules. Set a maximum of 100 RoutingRule Struct
ConditionErrorCode Specify redirect error code. Only 4XX error code can be configured. Priority is higher than Error.Key. String
ConditionPrefix Specifies the path to the prefix redirection, replacing the specified folder/ String
RedirectProtocol Protocol, which specifies the redirection, can only be set to https. String
RedirectReplaceKey Replace the entire Key with the specified content String
RedirectReplaceKeyPrefix Replace the prefix that matches to the specified content, and the Conditon can only be set to KeyPrefixEquals. String

Delete static site configuration

Function description

DELETE Bucket website is used to delete the static website configuration in Bucket.

Method prototype

func (s *BucketService) DeleteWebsite(ctx context.Context) (*Response, error)

Request Sample

resp, err = s.Client.Bucket.DeleteWebsite(context.Background())