Use the Content Moderation Go SDK to delete a custom person from your person library. Deleting a person permanently removes all associated face images and related information.
For the full list of request parameters, see DeletePerson.
Prerequisites
Before you begin, ensure that you have:
Installed the Go SDK dependencies using the Go version specified in Installation. Using an unsupported Go version causes subsequent API calls to fail.
Usage notes
Use the AI Guardrails API endpoints when calling the SDK. For endpoint details, see Endpoints.
Delete a person
Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
personId | Yes | String | The ID of the custom person to delete. |
Sample code
The following example deletes a custom person by their person ID. A successful request returns HTTP status code 200.
package main
import (
"encoding/json"
"fmt"
"os"
"strconv"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)
func main() {
// Reuse the client instance across requests to improve performance
// and avoid repeated connection overhead.
// Load credentials from environment variables — do not hardcode them.
client, err := green.NewClientWithAccessKey(
"cn-shanghai",
os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
)
if err != nil {
fmt.Println(err.Error())
return
}
content, _ := json.Marshal(map[string]interface{}{
"personId": "<person-id>", // Required: the ID of the custom person
})
request := green.CreateDeletePersonRequest()
request.SetContent(content)
response, err := client.DeletePerson(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("Request failed. HTTP status code: " + strconv.Itoa(response.GetHttpStatus()))
return
}
fmt.Println(response.GetHttpContentString())
}Replace <person-id> with the ID of the person to delete.
Set theALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables to your RAM user's AccessKey ID and AccessKey secret before running the code.
该文章对您有帮助吗?