feat(backend): 实现Go后端API并添加测试脚本
This commit is contained in:
68
background/test_scripts/generate_fake_files.go
Normal file
68
background/test_scripts/generate_fake_files.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 生成指定大小的随机字节数据
|
||||
func generateRandomData(size int64) []byte {
|
||||
data := make([]byte, size)
|
||||
_, err := rand.Read(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// 生成假文件
|
||||
func generateFakeFiles() {
|
||||
// 确保输出目录存在
|
||||
outputDir := "fake_files"
|
||||
err := os.MkdirAll(outputDir, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 定义要生成的文件类型和大小
|
||||
fileTypes := []string{".apk", ".ipa", ".zip", ".txt", ".pdf"}
|
||||
fileSizes := []int64{
|
||||
1024, // 1KB
|
||||
1024 * 1024, // 1MB
|
||||
5 * 1024 * 1024, // 5MB
|
||||
}
|
||||
|
||||
// 生成文件
|
||||
for i, size := range fileSizes {
|
||||
for _, ext := range fileTypes {
|
||||
filename := fmt.Sprintf("fake_file_%d_%d%s", i, len(ext), ext)
|
||||
filepath := filepath.Join(outputDir, filename)
|
||||
data := generateRandomData(size)
|
||||
err := os.WriteFile(filepath, data, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Generated %s (%d bytes)\n", filepath, size)
|
||||
}
|
||||
}
|
||||
|
||||
// 生成一个空文件
|
||||
emptyFile := filepath.Join(outputDir, "empty.txt")
|
||||
err = os.WriteFile(emptyFile, []byte{}, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Generated %s (0 bytes)\n", emptyFile)
|
||||
}
|
||||
|
||||
func main() {
|
||||
// 初始化随机数生成器
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
fmt.Println("Generating fake files...")
|
||||
generateFakeFiles()
|
||||
fmt.Println("Fake files generated successfully!")
|
||||
}
|
||||
Reference in New Issue
Block a user