Help Center/ ImageSearch/ SDK Reference/ Using the Go SDK/ Modifying Image Information
Updated on 2022-02-22 GMT+08:00

Modifying Image Information

This section describes how to modify an image using AK/SK authentication.

Replace the AK/SK in the sample code with the actual AK/SK. Set the Path and Tags parameters in the initialized RunModifyPictureReq command to change the path and tags of an image. After the configuration is complete, run the code.

  1. The sample code for modifying image information is as follows:
    package main 
    
     
    import (
        "fmt"
        "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v1"
        "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v1/region"
    )
     
    func main() {
        // Set the obtained AK and SK.
        ak := "<YOUR AK>"
        sk := "<YOUR SK>"
     
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
        // Set the request client. In this example, CN North-Beijing4 is used.
        client := imagesearch.NewImageSearchClient(
            imagesearch.ImagesearchClientBuilder().
                WithRegion(region.ValueOf("cn-north-4")).
                WithCredential(auth).
                Build())
     
        request := &model.RunModifyPictureRequest{
            InstanceName: "instance-name",
        }
        // Set the URL and tags of the image.
        var tags interface{}
        tags = map[string]string{"animal": "dog"}
        request.Body = &model.RunModifyPictureReq{
            Path: "https://bucketname.obs.cn-north-4.myhuaweicloud.com/imagesearch/test.jpg",
            Tags: &tags,
        }
        response, err := client.RunModifyPicture(request)
        if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
  2. Execute the sample code. If the instance deletion result is displayed on the console, the code is successfully executed. For details, see Modifying Image Information.
    RunModifyPictureResponse {"result":"Success."}