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

Torch Log Service

Copy page
Download PDF
Go SDK
Import the TOS data via Go SDK
Copy page
Download PDF
Import the TOS data via Go SDK
TLS supports importing TOS data via SDK. This document uses sample code to demonstrate how to import data from TOS to TLS using the Go SDK.​
Prerequisites​
  • TLS Go SDK has been installed. For more information, see Install Go SDK.​
  • The following commands have been executed to install the proto dependency package.​
  • ​
    go get -u github.com/gogo/protobuf/proto​
    ​
  • The VOLCENGINE_ACCESS_KEY_ID and other environment variables have been added. For instructions on configuring environment variables, please refer to Configure authentication information.​
warning​
It is recommended to dynamically obtain Volcano Engine keys and other authentication credentials via environment variables to prevent data security risks caused by hardcoding the AccessKey.​
Scenario description​
This document uses example code to demonstrate how to create a TOS data import task in a specified Project using the GO SDK. For information about relevant features, cautions, and fees, please refer to Import logs from TOS.​
Sample code​
​
package demo​
​
import (​
"github.com/volcengine/volc-sdk-golang/service/tls"​
"os"​
)​
​
func CreateImportTosTaskDemo() (*tls.CreateImportTaskResponse, error) {​
// Initialize the client. It is recommended to dynamically obtain identity authentication information such as the Volcano Engine key through environment variables to avoid data security risks caused by hard-coding the AccessKey. For detailed instructions, please refer to 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 import task.​
//For a description of the CreateImportTask API request parameters, see https://www.volcengine.com/docs/6470/1333757.​
createImportTaskResp, err := client.CreateImportTask(&tls.CreateImportTaskRequest{​
TopicID: "fa**",​
TaskName: "task-name-1",​
SourceType: "tos",​
Description: "this is a task",​
ImportSourceInfo: &tls.ImportSourceInfo{​
TosSourceInfo: &tls.TosSourceInfo{​
Bucket: "import01",​
Prefix: "accesslog/",​
Region: "cn-shanghai",​
CompressType: "snappy",​
},​
},​
TargetInfo: &tls.TargetInfo{​
Region: "cn-shanghai",​
LogType: "json_log",​
ExtractRule: &tls.ImportExtractRule{​
TimeZone: "GMT",​
SkipLineCount: 0,​
TimeExtractRegex: "",​
ExtractRule: &tls.ExtractRule{​
Quote: "\"",​
},​
},​
},​
})​
​
if err != nil {​
return nil, err​
}​
​
return createImportTaskResp, 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 related to data import tasks are as follows. You can refer to the API documentation to view detailed information about the corresponding interface.​
  • ​
    API​
    Description​
    Call the CreateImportTask API to create a data import task.​
    Call the DeleteImportTask API to delete the specified data import task.​
    Call the ModifyImportTask API to modify a specific data import task.​
    Call the DescribeImportTask API to obtain information about a specific data import task.​
    Call the DescribeImportTasks API to obtain the list of data import tasks.​
    ​
​
Last updated: 2025.10.11 16:44:08