Queries the details of a custom person by their person ID using the Go SDK.
For the full parameter reference, see API operation for querying person information.
Prerequisites
Before you begin, ensure that you have:
Go dependencies installed with the required Go version. See Installation for version requirements. Using a different Go version causes API calls to fail.
The AI Guardrails API endpoint configured. See Endpoint.
Query person information
The following example queries a custom person by their personId.
Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
personId | Yes | String | The ID of the custom person. Example: person-001 |
Code example
Store your AccessKey ID and AccessKey secret in environment variables rather than hardcoding them. Hardcoded credentials are a security risk if your code is shared or version-controlled.
Reuse the client instance across calls. Creating a new client for each request degrades performance and causes unnecessary connection overhead.
package main
import (
"encoding/json"
"fmt"
"os"
"strconv"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)
func main() {
// Initialize the client with your RAM user credentials from environment variables.
// Use the AI Guardrails API endpoint region: cn-shanghai.
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
}
// Set the personId of the custom person to query.
content, _ := json.Marshal(
map[string]interface{}{
"personId": "<your-person-id>",
},
)
request := green.CreateGetPersonRequest()
request.SetContent(content)
response, err := client.GetPerson(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 <your-person-id> with the ID of the custom person to query.
What's next
API operation for querying person information — full parameter reference
Endpoint — AI Guardrails API endpoints
Installation — Go SDK installation