You need to enable JavaScript to run this app.
导航
点播 CDN
最近更新时间:2024.09.29 17:41:41首次发布时间:2022.03.31 15:59:02

本文为您提供了服务端 Go SDK 的点播 CDN 模块的接口调用示例。

前提条件

调用接口前,请先完成 SDK 的安装初始化

调用示例

创建域名

接口请求参数和返回参数详见 OpenAPI:创建域名

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_CreateDomain(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodCreateDomainV2Request{
                SpaceName:                "your SpaceName",
                DomainType:               "your DomainType",
                Domain:                   "your Domain",
                SourceStationType:        0,
                SourceStationAddressType: 0,
                Origins:                  "your Origins",
                Area:                     "your Area",
                BucketName:               "your BucketName",
        }

        resp, status, err := instance.CreateDomain(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

启用域名

接口请求参数和返回参数详见 OpenAPI:启用域名

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_StartDomain(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodStartDomainRequest{
                SpaceName:         "your SpaceName",
                DomainType:        "your DomainType",
                Domain:            "your Domain",
                SourceStationType: 0,
        }

        resp, status, err := instance.StartDomain(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

停用域名

接口请求参数和返回参数详见 OpenAPI:停用域名

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_StopDomain(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodStopDomainRequest{
                SpaceName:         "your SpaceName",
                DomainType:        "your DomainType",
                Domain:            "your Domain",
                SourceStationType: 0,
        }

        resp, status, err := instance.StopDomain(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

删除域名

接口请求参数和返回参数详见 OpenAPI:删除域名

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_DeleteDomain(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodDeleteDomainRequest{
                SpaceName:  "your SpaceName",
                DomainType: "your DomainType",
                Domain:     "your Domain",
        }

        resp, status, err := instance.DeleteDomain(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

获取空间域名列表

接口请求参数和返回参数详见 OpenAPI:获取空间域名列表

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_ListDomain(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodListDomainRequest{
                SpaceName:         "your SpaceName",
                DomainType:        "your DomainType",
                SourceStationType: 0,
                Offset:            0,
                Limit:             0,
        }

        resp, status, err := instance.ListDomain(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

将域名添加至点播调度

接口请求参数和返回参数详见 OpenAPI:将域名添加至点播调度

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_AddDomainToScheduler(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodAddDomainToSchedulerRequest{
                SpaceName:         "your SpaceName",
                DomainType:        "your DomainType",
                Domain:            "your Domain",
                SourceStationType: 0,
        }

        resp, status, err := instance.AddDomainToScheduler(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

将域名移除点播调度

接口请求参数和返回参数详见 OpenAPI:将域名移除点播调度

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_RemoveDomainFromScheduler(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodRemoveDomainFromSchedulerRequest{
                SpaceName:         "your SpaceName",
                DomainType:        "your DomainType",
                Domain:            "your Domain",
                SourceStationType: 0,
        }

        resp, status, err := instance.RemoveDomainFromScheduler(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

设置域名分发规则

接口请求参数和返回参数详见 OpenAPI:设置域名分发规则

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_UpdateDomainPlayRule(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodUpdateDomainPlayRuleRequest{
                SpaceName:     "your SpaceName",
                DefaultDomain: "your DefaultDomain",
                PlayRule:      "your PlayRule",
        }

        resp, status, err := instance.UpdateDomainPlayRule(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

修改域名时间戳防盗链

接口请求参数和返回参数详见 OpenAPI:修改域名时间戳防盗链

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_UpdateDomainExpire(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodUpdateDomainExpireV2Request{
                SpaceName:  "your SpaceName",
                DomainType: "your DomainType",
                Domain:     "your Domain",
                Expire:     0,
        }

        resp, status, err := instance.UpdateDomainExpire(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

修改域名 URL 鉴权配置

接口请求参数和返回参数详见 OpenAPI:修改域名 URL 鉴权配置

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_UpdateDomainUrlAuthConfig(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodUpdateDomainUrlAuthConfigV2Request{
                SpaceName:  "your SpaceName",
                DomainType: "your DomainType",
                Domain:     "your Domain",
                MainKey:    "your MainKey",
                BackupKey:  "your BackupKey",
                Status:     "your Status",
        }

        resp, status, err := instance.UpdateDomainUrlAuthConfig(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

刷新缓存

接口请求参数和返回参数详见 OpenAPI:刷新缓存

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_CreateCdnRefreshTask(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodCreateCdnRefreshTaskRequest{
                SpaceName: "your SpaceName",
                Urls:      "your Urls",
                Type:      "your Type",
        }

        resp, status, err := instance.CreateCdnRefreshTask(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

预热缓存

接口请求参数和返回参数详见 OpenAPI:预热缓存

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_CreateCdnPreloadTask(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodCreateCdnPreloadTaskRequest{
                SpaceName: "your SpaceName",
                Urls:      "your Urls",
        }

        resp, status, err := instance.CreateCdnPreloadTask(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

获取刷新预热任务列表

接口请求参数和返回参数详见 OpenAPI:获取刷新预热任务列表

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_ListCdnTasks(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodListCdnTasksRequest{
                SpaceName:      "your SpaceName",
                TaskId:         "your TaskId",
                DomainName:     "your DomainName",
                TaskType:       "your TaskType",
                Status:         "your Status",
                StartTimestamp: 0,
                EndTimestamp:   0,
                PageNum:        0,
                PageSize:       0,
        }

        resp, status, err := instance.ListCdnTasks(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

获取日志文件下载地址

接口请求参数和返回参数详见 OpenAPI:获取日志文件下载地址

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
)

func Test_ListCdnAccessLog(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see  https://www.volcengine.com/docs/4/65655.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodListCdnAccessLogRequest{
                Domains:        "your Domains",
                StartTimestamp: 0,
                EndTimestamp:   0,
                SpaceName:      "your SpaceName",
        }

        resp, status, err := instance.ListCdnAccessLog(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}