Integrate the Go server-side SDK
This topic describes how to integrate the Captcha server-side SDK for Go.
Prerequisites
You have an AccessKey for your Alibaba Cloud account.
The Go server-side SDK package has been downloaded and unzipped.
A Go development environment of version 1.12.0 or later.
Install the SDK
Locate the client file in the unzipped Go server-side SDK package.
Import the client package into your server-side project.
After the package is added, you can use the Alibaba Cloud Captcha Go SDK in your server-side project.
Notes
The client package contains the classes for the Alibaba Cloud Captcha server-side SDK.
The default connection timeout for API calls is 3 seconds, and the default read timeout is 80 seconds. To customize these timeouts, call the constructor with the
connectTimeoutandreadTimeoutparameters.
Initialize IClientProfile
IClientProfile is the interface for interacting with the Alibaba Cloud Captcha server-side. You can perform all SDK operations using IClientProfile.
IClientProfile is reusable. We recommend that you set it as a global and unique instance in your application.
import (
"fmt"
afs "github.com/alibabacloud-go/afs-20180112/client"
rpc "github.com/alibabacloud-go/tea-rpc/client"
)
config := new(rpc.Config)
config.SetAccessKeyId("*** Provide your AccessKeyId ***").
SetAccessKeySecret("*** Provide your AccessKeySecret ***").
SetRegionId("cn-hangzhou").
SetEndpoint("afs.aliyuncs.com")
client, _ := afs.NewClient(config)Call the Alibaba Cloud Captcha server-side API
After you configure IClientProfile, you can call the AnalyzeNvcRequest interface and, based on your business needs, develop a handler class for frontend page requests and a method to process the results.
request := new(afs.AuthenticateSigRequest)
request.SetSig("xxx")
request.SetSessionId("xxx")
request.SetToken("xxx")
request.SetRemoteIp("xxx")
request.SetScene("xxx")
request.SetAppKey("xxx")
response,_err := client.AuthenticateSig(request)
fmt.Println(response)