You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
Go SDK
Send logs to TOS using Go SDK
Copy page
Download PDF
Send logs to TOS using Go SDK
TLS supports delivering logs to TOS via SDK. This document uses example code to demonstrate how to deliver logs to TOS using the Go SDK.​
Prerequisites​
  • The TLS Go SDK has been installed. For more information, see Install Go SDK.​
  • The following commands have been executed to install the proto dependencies.​
  • ​
    go get -u github.com/gogo/protobuf/proto​
    ​
  • The VOLCENGINE_ACCESS_KEY_ID and other environment variables have been added. For the method of configuring environment variables, please refer to Configure authentication information.​
warning​
It is recommended to dynamically obtain Volcengine keys and other authentication information through environment variables to avoid the data security risks caused by hardcoding AccessKey.​
Scenario description​
This document demonstrates, through example code, how to use the GO SDK to create a configuration for delivering logs to TOS in a specified Project. Please refer to Overview for related notes and fee information.​
Sample code​
​
package demo​
​
import (​
"github.com/volcengine/volc-sdk-golang/service/tls"​
"os"​
"time"​
)​
​
func CreateShipperTosDemo() (*tls.CreateShipperResponse, error) {​
// When initializing the client, it's recommended to dynamically obtain the Volcano Engine key and other authentication information through environment variables to avoid data security risks caused by hard-coding the AccessKey. For detailed instructions, see https://www.volcengine.com/docs/6470/1166455.​
// When using STS, both ak and sk use temporary keys and set VOLCENGINE_TOKEN; when not using STS, the VOLCENGINE_TOKEN part is passed empty.​
client := tls.NewClient(os.Getenv("VOLCENGINE_ENDPOINT"), os.Getenv("VOLCENGINE_ACCESS_KEY_ID"), os.Getenv("VOLCENGINE_ACCESS_KEY_SECRET"), os.Getenv("VOLCENGINE_TOKEN"), os.Getenv("VOLCENGINE_REGION"))​
//Create a data delivery configuration.​
//For a description of the CreateShipper API request parameters, see https://www.volcengine.com/docs/6470/1333747.​
createShipperRes, err := client.CreateShipper(&tls.CreateShipperRequest{​
TopicId: "c7****",​
ShipperName: "tosship",​
ShipperType: "tos",​
ShipperStartTime: int(time.Now().UnixMilli()),​
ShipperEndTime: int(time.Now().UnixMilli()) + 3600*1000,​
TosShipperInfo: &tls.TosShipperInfo{​
Bucket: "mytos",​
Prefix: "testprefix",​
MaxSize: 10,​
Compress: "none",​
Interval: 900,​
PartitionFormat: "%Y/%m/%d/%H",​
},​
ContentInfo: &tls.ContentInfo{​
Format: "json",​
JsonInfo: &tls.JsonInfo{​
Keys: []string{"__content__", "__source__", "__path__"},​
Enable: true,​
Escape: true,​
},​
},​
})​
​
if err != nil {​
return nil, err​
}​
​
return createShipperRes, nil​
}​
​
Related documentation​
  • After you send an API request through the SDK, you will receive a response from the server. If the response contains a status code other than 200, it indicates that the API call has failed. You can refer to the documentation for each API to view the corresponding error code information.​
  • The API interfaces involved in this example are as follows. You can refer to the API documentation to view detailed information about the corresponding interface.​
  • ​
    API​
    Description​
    Call the CreateShipper API to create a delivery configuration.​
    Call the DeleteShipper API to delete the specified delivery configuration.​
    Call the ModifyShipper API to modify the specified delivery configuration.​
    Call the DescribeShipper API to obtain detailed information about the delivery configuration.​
    Call the DescribeShippers API to obtain the delivery configuration list.​
    ​
​
Last updated: 2025.10.11 16:44:08