首次提交:初始化项目代码

This commit is contained in:
sunct
2026-07-31 15:18:32 +08:00
commit d6393266b0
193 changed files with 14287 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"encoding/json"
"fmt"
"os"
)
// Product 大数据模型
type Product struct {
SKU string `json:"sku"`
Price float64 `json:"price"`
}
func main() {
// 流式写入
file, _ := os.Create("json/bulma_products.json")
defer file.Close()
enc := json.NewEncoder(file)
for i := 1; i <= 5000; i++ {
_ = enc.Encode(Product{
SKU: fmt.Sprintf("BULMA%05d", i),
Price: 99.9,
})
}
fmt.Println("\n流式写入完成")
// 流式读取
rf, _ := os.Open("json/bulma_products.json")
defer rf.Close()
dec := json.NewDecoder(rf)
count := 0
for dec.More() {
var p Product
_ = dec.Decode(&p)
count++
}
fmt.Printf("流式解析完成,总数:%d\n", count)
}