All Products
Search
Document Center

Snapshot template

Last Updated: Jul 11, 2019

Initialize a client

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

Add a snapshot template

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

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"
    "encoding/json"
    "fmt"
)

func MyAddVodTemplate(client *vod.Client) (response *vod.AddVodTemplateResponse, err error) {
    request := vod.CreateAddVodTemplateRequest()

    // Sets the template name.
    request.Name = "Sample Snapshot Template"
    // Sets the template type to Snapshot.
    request.TemplateType = "Snapshot"

    // Generates the snapshot template configuration.
    snapshotConfig := map[string]interface{}{"Count": 50, "Interval": 1, "SpecifiedOffsetTime": 0, "Width": 200,
        "Height": 200, "FrameType": "normal"}
    templateConfig := map[string]interface{}{"SnapshotConfig": snapshotConfig, "SnapshotType": "NormalSnapshot"}

    /*
    // (Optional) Specifies the sprite snapshot configuration, which must be constructed based on the normal snapshot configuration.
    spriteSnapshotConfig := map[string]interface{}{"CellWidth": 120, "CellHeight": 68, "Columns": 3, "Lines": 10,
        "Padding": 20, "Margin": 50, "KeepCellPic": "keep", "Color": "tomato"}
    snapshotConfig["SpriteSnapshotConfig"] = spriteSnapshotConfig
    templateConfig["SnapshotType"] = "SpriteSnapshot"
    */

    jsonConfig, err := json.Marshal(templateConfig)
    if err ! = nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.TemplateConfig = string(jsonConfig)

    request.AcceptFormat = "JSON"

    return client.AddVodTemplate(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.VodTemplateId)
}

Modify a snapshot template

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

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"
    "encoding/json"
    "fmt"
)

func MyUpdateVodTemplate(client *vod.Client) (response *vod.UpdateVodTemplateResponse, err error) {
    request := vod.CreateUpdateVodTemplateRequest()

    request.VodTemplateId = "c0825c5f4c4a43af56abf9826b2d4e4f"
    // Sets the template name.
    request.Name = "New Snapshot Template Name"

    // Modifies the snapshot template configuration.
    snapshotConfig := map[string]interface{}{"Count": 50, "Interval": 1, "SpecifiedOffsetTime": 0, "Width": 200,
        "Height": 200, "FrameType": "normal"}
    templateConfig := map[string]interface{}{"SnapshotConfig": snapshotConfig, "SnapshotType": "NormalSnapshot"}

    jsonConfig, err := json.Marshal(templateConfig)
    if err ! = nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.TemplateConfig = string(jsonConfig)

    request.AcceptFormat = "JSON"

    return client.UpdateVodTemplate(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

Delete a snapshot template

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

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"
    "encoding/json"
    "fmt"
)

func MyDeleteVodTemplate(client *vod.Client) (response *vod.DeleteVodTemplateResponse, err error) {
    request := vod.CreateDeleteVodTemplateRequest()
    request.VodTemplateId = "<TemplateId>" 

    request.AcceptFormat = "JSON"

    return client.DeleteVodTemplate(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

Query a list of snapshot templates

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

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"
    "encoding/json"
    "fmt"
)

func MyListVodTemplate(client *vod.Client) (response *vod.ListVodTemplateResponse, err error) {
    request := vod.CreateListVodTemplateRequest()
    // Sets the template type to Snapshot.
    request.TemplateType = "Snapshot"

    request.AcceptFormat = "JSON"

    return client.ListVodTemplate(request)
}

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

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

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    for _, template := range response.VodTemplateInfoList {
        fmt.Printf("%s: %s %s\n", template.VodTemplateId, template.Name, template.TemplateConfig)
    }
}

Query a snapshot template

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

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"
    "encoding/json"
    "fmt"
)

func MyGetVodTemplate(client *vod.Client) (response *vod.GetVodTemplateResponse, err error) {
    request := vod.CreateGetVodTemplateRequest()
    request.VodTemplateId = "<TemplateId>"

    request.AcceptFormat = "JSON"

    return client.GetVodTemplate(request)
}

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

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

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