Release Notes
Announcements
go get github.com/tencentcloud/tencentcloud-cls-sdk-go
import ("fmt""github.com/TencentCloud/tencentcloud-cls-sdk-go")
Variable | Type | Required | Description |
Endpoint | String | Yes | Domain information. For completion, see the domain name in the Log upload via API Tab of available region. |
AccessKeyID | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
AccessKeySecret | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
topicId | String | Yes | Log topic ID information. |
package main// Import the CLS Go SDKimport ("fmt""github.com/tencentcloud/tencentcloud-cls-sdk-go""sync""os""time")func main() {producerConfig := tencentcloud_cls_sdk_go.GetDefaultAsyncProducerClientConfig()// Fill in domain information. Completion guide: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8D. See the domain name in the Log upload via API Tab of the link.producerConfig.Endpoint = "ap-XXXXXXXXX.cls.xxxxxxx.com"// Fill in TencentCloud API Key Information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi// Please ensure the associated account has appropriate log upload permissions. Permission configuration guide: https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE// This example retrieves from environmental variable. Environment variable configuration guide: https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1producerConfig.AccessKeyID = os.Getenv("TENCENTCLOUD_SECRET_ID")producerConfig.AccessKeySecret = os.Getenv("TENCENTCLOUD_SECRET_KEY")// Set the topic ID for log upload, replace with your Topic IDtopicId := "8bbXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"// Create an asynchronous producer client instanceproducerInstance, err := tencentcloud_cls_sdk_go.NewAsyncProducerClient(producerConfig)if err != nil {fmt.Println(err)return}// Start the asynchronous sender programproducerInstance.Start()var m sync.WaitGroupcallBack := &Callback{}for i := 0; i < 10; i++ {m.Add(1)go func() {defer m.Done()for i := 0; i < 1000; i++ {// Create a new log with the current timestamp and log contentlog := tencentcloud_cls_sdk_go.NewCLSLog(time.Now().Unix(), map[string]string{"content": "hello world| I'm from XXX", "content2": fmt.Sprintf("%v", i)})err = producerInstance.SendLog(topicId, log, callBack)if err != nil {fmt.Println(err)continue}}}()}m.Wait()producerInstance.Close(60000)}type Callback struct {}func (callback *Callback) Success(result *tencentcloud_cls_sdk_go.Result) {attemptList := result.GetReservedAttempts()for _, attempt := range attemptList {fmt.Printf("%+v \\n", attempt)}}func (callback *Callback) Fail(result *tencentcloud_cls_sdk_go.Result) {fmt.Println(result.IsSuccessful())fmt.Println(result.GetErrorCode())fmt.Println(result.GetErrorMessage())fmt.Println(result.GetReservedAttempts())fmt.Println(result.GetRequestId())fmt.Println(result.GetTimeStampMs())}
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback