refactor: 将布隆过滤器改为Cuckoo过滤器并优化代码结构
All checks were successful
构建上传工具 / build-tool (push) Successful in 59s
部署开发环境 / deploy-dev (push) Successful in 1m36s

This commit is contained in:
2025-09-12 22:26:45 +08:00
parent 5d304b6334
commit 1c56423ea4
4 changed files with 83 additions and 72 deletions

View File

@@ -26,6 +26,41 @@ var httpClient = &http.Client{
}
func main() {
initConfig()
//检测./upload
fmt.Println("程序启动成功正在检测txt文件")
for {
files, err := getTxtFiles("./")
if err != nil {
fmt.Println(err)
return
}
if files != nil {
start := time.Now()
wg := sync.WaitGroup{}
for _, filePath := range files {
fmt.Println("正在上传文件:", filePath)
wg.Add(1)
go func() {
processFile(filePath)
err := os.Truncate(filePath, 0)
if err != nil {
fmt.Println("清空文件失败:", err)
}
wg.Done()
}()
}
wg.Wait()
fmt.Println("上传完成,耗时:", time.Since(start))
}
time.Sleep(time.Minute)
}
}
func initConfig() {
//程序配置
viper.SetDefault("url", "http://localhost:8080")
viper.SetDefault("token", "")
@@ -45,33 +80,6 @@ func main() {
fmt.Errorf("无法读取配置文件: %w", err)
}
})
//检测./upload
fmt.Println("程序启动成功正在检测txt文件")
for {
files, err := getTxtFiles("./")
if err != nil {
fmt.Println(err)
return
}
if files != nil {
wg := sync.WaitGroup{}
for _, filePath := range files {
fmt.Println("正在上传文件:", filePath)
wg.Add(1)
go func() {
processFile(filePath)
err := os.Truncate(filePath, 0)
if err != nil {
fmt.Println("清空文件失败:", err)
}
wg.Done()
}()
}
wg.Wait()
}
time.Sleep(time.Minute)
}
}
func uploadDataToServer(data string) error {