Help Center/ ImageSearch/ SDK Reference/ Using the Go SDK/ Querying Details About an Instance
Updated on 2022-02-22 GMT+08:00

Querying Details About an Instance

This section describes how to query an instance using AK/SK authentication.

Replace the AK/SK in the sample code with the actual AK/SK. Set the InstanceName parameter in the RunQueryInstanceRequest command to specify the name of the instance you want to query. After the configuration is complete, run the code.

  1. The sample code for querying an instance 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())
        //Set the instance name.
        request := &model.RunQueryInstanceRequest{
            InstanceName: "instance-name",
        }
        
        response, err := client.RunQueryInstance(request)
        if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
  2. Execute the sample code. If the instance querying result is displayed on the console, the code is successfully executed. For details, see Querying the Details About an Instance.
    RunQueryInstanceResponse {"domain": "general image search","desc":"","registerDate":1638344126274,"expiredDate":-1,"level":30000000,"tags":["animal","plant"],"status":"NORMAL","instanceName":"instance-name"}