feat(data): 添加数据格式支持 更改数据写入读取
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
This commit is contained in:
@@ -16,19 +16,6 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type UploadData struct {
|
||||
Dyid string // dyid
|
||||
Uid string // uid
|
||||
Secid string // secid
|
||||
Pid string // pid
|
||||
CommentId string // comment_id
|
||||
Id1 string // id1
|
||||
Id2 string // id2
|
||||
Id3 string // id3
|
||||
Id4 string // id4
|
||||
Id5 string // id5
|
||||
}
|
||||
|
||||
var httpClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 200,
|
||||
@@ -43,10 +30,6 @@ func main() {
|
||||
viper.SetDefault("url", "http://localhost:8080")
|
||||
viper.SetDefault("token", "")
|
||||
viper.SetDefault("thread-count", 10)
|
||||
viper.SetDefault("index.uid", 0)
|
||||
viper.SetDefault("index.secid", 1)
|
||||
viper.SetDefault("index.pid", 2)
|
||||
viper.SetDefault("index.comment-id", 3)
|
||||
//设置配置文件名和路径 ./config.toml
|
||||
viper.AddConfigPath(".")
|
||||
viper.SetConfigName("config")
|
||||
@@ -89,19 +72,10 @@ func main() {
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}
|
||||
func uploadDataToServer(data UploadData) error {
|
||||
func uploadDataToServer(data string) error {
|
||||
params := url.Values{}
|
||||
params.Add("token", viper.GetString("token"))
|
||||
params.Add("dyid", data.Dyid)
|
||||
params.Add("uid", data.Uid)
|
||||
params.Add("secid", data.Secid)
|
||||
params.Add("pid", data.Pid)
|
||||
params.Add("comment_id", data.CommentId)
|
||||
params.Add("id1", data.Id1)
|
||||
params.Add("id2", data.Id2)
|
||||
params.Add("id3", data.Id3)
|
||||
params.Add("id4", data.Id4)
|
||||
params.Add("id5", data.Id5)
|
||||
params.Set("token", viper.GetString("token"))
|
||||
params.Set("data", data)
|
||||
|
||||
resp, err := httpClient.Post(viper.GetString("url")+"/api/data?"+params.Encode(), "application/x-www-form-urlencoded", strings.NewReader(""))
|
||||
if err != nil {
|
||||
@@ -188,35 +162,8 @@ func processLines(lines <-chan string, workerID int, filePath string) {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 使用----分割行数据
|
||||
parts := strings.Split(line, "----")
|
||||
for i := 0; i < 10; i++ {
|
||||
parts = append(parts, "")
|
||||
}
|
||||
|
||||
// 确保有足够的字段
|
||||
if len(parts) < 3 {
|
||||
fmt.Printf("Worker %d (文件 %s): 行数据字段不足,跳过: %s\n", workerID, filePath, line)
|
||||
continue
|
||||
}
|
||||
|
||||
// 创建上传数据结构
|
||||
uploadData := UploadData{
|
||||
Uid: parts[viper.GetInt("index.uid")],
|
||||
Secid: parts[viper.GetInt("index.secid")],
|
||||
Pid: parts[viper.GetInt("index.pid")],
|
||||
CommentId: parts[viper.GetInt("index.comment-id")],
|
||||
Dyid: parts[4],
|
||||
Id1: parts[5],
|
||||
Id2: parts[6],
|
||||
Id3: parts[7],
|
||||
Id4: parts[8],
|
||||
Id5: parts[9],
|
||||
}
|
||||
|
||||
// 上传数据
|
||||
if err := uploadDataToServer(uploadData); err != nil {
|
||||
if err := uploadDataToServer(line); err != nil {
|
||||
fmt.Printf("Worker %d (文件 %s): 上传失败: %v\n", workerID, filePath, err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user