All Products
Search
Document Center

CDN

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Preload content to cache nodes

For more information about the request and response parameters, see PreloadVodObjectCaches.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
    "strings"
)

func MyPreloadVodObjectCaches(client *vod.Client) (response *vod.PreloadVodObjectCachesResponse, err error) {
    request := vod.CreatePreloadVodObjectCachesRequest()
    objectPath := []string{"http://test.com/fd.mp4", "http://test.com/ld.mp4"}
    request.ObjectPath = strings.Join(objectPath, "\n")

    request.AcceptFormat = "JSON"

    return client.PreloadVodObjectCaches(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>") 
    if err ! = nil {
        panic(err)
    }

    response, err := MyPreloadVodObjectCaches(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    fmt.Printf("PreloadTaskId: %s\n", response.PreloadTaskId)
}

Refresh the cached content on nodes

For more information about the request and response parameters, see RefreshVodObjectCaches.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
    "strings"
)

func MyRefreshVodObjectCaches(client *vod.Client) (response *vod.RefreshVodObjectCachesResponse, err error) {
    request := vod.CreateRefreshVodObjectCachesRequest()
    objectPath := []string{"http://test.com/fd.mp4", "http://test.com/ld.mp4"}
    request.ObjectPath = strings.Join(objectPath, "\n")

    request.AcceptFormat = "JSON"

    return client.RefreshVodObjectCaches(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>") 
    if err ! = nil {
        panic(err)
    }

    response, err := MyRefreshVodObjectCaches(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    fmt.Printf("RefreshTaskId: %s\n", response.RefreshTaskId)
}

Query the status of refresh and preload tasks

For more information about the request and response parameters, see DescribeVodRefreshTasks.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDescribeVodRefreshTasks(client *vod.Client) (response *vod.DescribeVodRefreshTasksResponse, err error) {
    request := vod.CreateDescribeVodRefreshTasksRequest()
    request.DomainName = "test.com"
    request.ObjectType = "preload"

    request.AcceptFormat = "JSON"

    return client.DescribeVodRefreshTasks(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyDescribeVodRefreshTasks(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    for _, task := range response.Tasks.Task {
        fmt.Printf("%s: %s %s\n", task.ObjectPath, task.Status, task.Process)
    }
}

Query the maximum number and remaining number of requests to refresh and preload content on the current day

For more information about the request and response parameters, see DescribeVodRefreshQuota.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDescribeVodRefreshQuota(client *vod.Client) (response *vod.DescribeVodRefreshQuotaResponse, err error) {
    request := vod.CreateDescribeVodRefreshQuotaRequest()

    request.AcceptFormat = "JSON"

    return client.DescribeVodRefreshQuota(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyDescribeVodRefreshQuota(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    fmt.Printf("PreloadQuota %s, PreloadRemain %s\n", response.PreloadQuota, response.PreloadRemain)
    fmt.Printf("UrlQuota %s, UrlRemain %s\n", response.UrlQuota, response.UrlRemain)
}

Obtain the network traffic monitoring data for accelerating domain names

For more information about the request and response parameters, see DescribeVodDomainTrafficData.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDescribeVodDomainTrafficData(client *vod.Client) (response *vod.DescribeVodDomainTrafficDataResponse, err error) {
    request := vod.CreateDescribeVodDomainTrafficDataRequest()
    request.DomainName = "test.com"
    request.StartTime = "2019-01-15T15:59:59Z"
    request.EndTime = "2019-01-20T15:59:58Z"

    request.AcceptFormat = "JSON"

    return client.DescribeVodDomainTrafficData(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyDescribeVodDomainTrafficData(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    for _, item := range response.TrafficDataPerInterval.DataModule {
        fmt.Printf("%s: DomesticValue %s bytes, OverseasValue %s bytes\n",
            item.TimeStamp, item.DomesticValue, item.OverseasValue)
    }
}

Obtain the network bandwidth monitoring data for accelerating domain names

For more information about the request and response parameters, see DescribeVodDomainBpsData.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDescribeVodDomainBpsData(client *vod.Client) (response *vod.DescribeVodDomainBpsDataResponse, err error) {
    request := vod.CreateDescribeVodDomainBpsDataRequest()
    request.DomainName = "test.com"
    request.StartTime = "2019-01-15T15:59:59Z"
    request.EndTime = "2019-01-20T15:59:58Z"

    request.AcceptFormat = "JSON"

    return client.DescribeVodDomainBpsData(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>") 
    if err ! = nil {
        panic(err)
    }

    response, err := MyDescribeVodDomainBpsData(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    for _, item := range response.BpsDataPerInterval.DataModule {
        fmt.Printf("%s: Value %s bps, OverseasValue %s bps\n",
            item.TimeStamp, item.Value, item.OverseasValue)
    }
}

Download raw CDN access logs for a specified domain name

For more information about the request and response parameters, see DescribeVodDomainLog.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDescribeVodDomainLog(client *vod.Client) (response *vod.DescribeVodDomainLogResponse, err error) {
    request := vod.CreateDescribeVodDomainLogRequest()
    request.DomainName = "vod-test1.cn-shanghai.aliyuncs.com"
    request.StartTime = "2019-01-15T15:59:59Z"
    request.EndTime = "2019-01-20T15:59:58Z"
    request.PageNumber = "1"
    request.PageSize = "300"

    request.AcceptFormat = "JSON"

    return client.DescribeVodDomainLog(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err ! = nil {
        panic(err)
    }

    response, err := MyDescribeVodDomainLog(client)
    if err ! = nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Printf("RequestId: %s\n", response.RequestId)
    logDetail := response.DomainLogDetails.DomainLogDetail[0]
    fmt.Printf("TotalLogCount: %d\n", logDetail.PageInfos.Total)
    for _, item := range logDetail.LogInfos.LogInfoDetail {
        fmt.Printf("%s: LogSize %d bytes, LogDownloadPath\n %s\n", 
            item.StartTime, item.LogSize, item.LogPath)
    }
}