This topic describes how to use the Go software development kit (SDK) to perform a paged query for all sample images in a specified similar-image library.
Description
You can call this operation to perform a paged query for all sample images in a specified similar-image library. For more information about the parameters, see Query a list of sample images.
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 sample images in a similar-image library
package main
import (
"encoding/json"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
"strconv"
)
func main() {
/**
* Note: To improve detection performance, reuse the instantiated client. This avoids repeatedly establishing connections.
* Common methods to obtain environment variables:
* To obtain the AccessKey ID of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* To obtain the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"<your-access-key-id>",
"<your-access-key-secret>")
if err != nil {
fmt.Println(err.Error())
return
}
// pageSize: The number of entries to return on each page. Valid values: (0, 50]. currentPage: The number of the page to return. Valid values: (0, 50].
content, _ := json.Marshal(
map[string]interface{}{
"library": "<your-library-name>", "pageSize": "5", "currentPage": 1,
},
)
request := green.CreateListSimilarityImagesRequest()
request.SetContent(content)
response, _err := client.ListSimilarityImages(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())
}
该文章对您有帮助吗?