This topic describes how to use the Go software development kit (SDK) to query similar image libraries and their elements by page.
Description
You can call this operation to query all similar image libraries and their elements by page. For more information about the parameters, see the ListSimilarityLibraries API reference.
You must use the Content Moderation endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.
Prerequisites
Go dependencies are installed. For more information, see Installation.
Note
You must use the required Go version described in the Installation topic to install the dependencies. Otherwise, subsequent operation calls fail.
Query a list of similar image libraries
package main
import (
"encoding/json"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
"strconv"
)
func main() {
/**
* Note: Reuse the instantiated client as much as possible to improve detection performance.
* This avoids establishing repeated connections.
* Common methods to obtain environment variables:
* Obtain the AccessKey ID of the Resource Access Management (RAM) user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* Obtain the AccessKey secret of the RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"Replace with the AccessKey ID of your RAM user",
"Replace with the AccessKey secret of your RAM user")
if err != nil {
fmt.Println(err.Error())
return
}
// pageSize: The number of entries per page. Valid values: (0, 50]. currentPage: The current page number. Valid values: (0, 50].
content, _ := json.Marshal(
map[string]interface{}{
"pageSize": "5", "currentPage": 1,
},
)
request := green.CreateListSimilarityLibrariesRequest()
request.SetContent(content)
response, _err := client.ListSimilarityLibraries(request)
if _err != nil {
fmt.Println(_err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("response not success. status:" + strconv.Itoa(response.GetHttpStatus()))
}
fmt.Println(response.GetHttpContentString())
}该文章对您有帮助吗?