This topic describes how to use the Go software development kit (SDK) to remove similar image samples from an image library.
Description
The removal operation takes effect within one minute. You can remove up to 100 sample images at a time. For more information about the parameters, see the DeleteSampleImage API documentation.
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.
Remove similar image samples
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 client instance.
* This avoids establishing new connections for each request.
* Common methods for getting environment variables:
* Get the AccessKey ID of a Resource Access Management (RAM) user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
* Get the AccessKey secret of a RAM user: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
*/
client, _err := green.NewClientWithAccessKey(
"cn-shanghai",
"Get the RAM user AccessKey ID from an environment variable",
"Get the RAM user AccessKey secret from an environment variable")
if err != nil {
fmt.Println(err.Error())
return
}
content, _ := json.Marshal(
map[string]interface{}{
"dataIds": [...]string{"Sample image ID 1", "Sample image ID 2"},
},
)
request := green.CreateDeleteSimilarityImageRequest()
request.SetContent(content)
response, _err := client.DeleteSimilarityImage(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())
}该文章对您有帮助吗?