1
0
mirror of https://github.com/FloatTech/zbpdata.git synced 2024-11-17 09:37:14 +09:00
zbpdata/main.go

69 lines
1.4 KiB
Go
Raw Normal View History

2022-03-27 14:27:16 +09:00
//go:build ignore
// +build ignore
2021-12-25 21:15:28 +09:00
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io/fs"
"os"
"strings"
2022-04-17 17:03:41 +09:00
"sync"
2021-12-25 21:15:28 +09:00
"unicode"
"unsafe"
"github.com/fumiama/go-registry"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
)
func main() {
var files []string
fs.WalkDir(os.DirFS("./"), ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() && strings.Contains(path, "/") && unicode.IsUpper([]rune(path)[0]) {
files = append(files, path)
}
return nil
})
fmt.Println(files)
md5s := make([]string, len(files))
for i, fn := range files {
data, err := os.ReadFile(fn)
if err != nil {
panic(err)
}
buf := md5.Sum(data)
*(*unsafe.Pointer)(unsafe.Pointer(&md5s[i])) = unsafe.Pointer(&buf)
*(*uintptr)(unsafe.Add(unsafe.Pointer(&md5s[i]), unsafe.Sizeof(uintptr(0)))) = uintptr(16)
}
2022-03-01 17:52:39 +09:00
r := registry.NewRegedit("reilia.westeurope.cloudapp.azure.com:32664", "fumiama", os.Getenv("REILIA_SPS"))
2021-12-25 21:15:28 +09:00
err := r.Connect()
if err != nil {
panic(err)
}
2022-04-17 17:03:41 +09:00
defer r.Close()
2022-04-17 21:32:57 +09:00
do1024 := func(k, v string) {
for i := 0; i < 1024; i++ {
err = r.Set(k, v)
if err == nil {
break
}
fmt.Println("accqiring set lock, retry times:", i)
2022-04-17 17:18:12 +09:00
}
}
2022-04-17 17:03:41 +09:00
var wg sync.WaitGroup
wg.Add(len(files))
2021-12-25 21:15:28 +09:00
for i, fn := range files {
2022-04-17 17:03:41 +09:00
go func(i int, fn string) {
2022-04-17 21:32:57 +09:00
do1024("data/"+fn, md5s[i])
fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i])))
wg.Done()
2022-04-17 17:03:41 +09:00
}(i, fn)
2021-12-25 21:15:28 +09:00
}
2022-04-17 17:03:41 +09:00
wg.Wait()
2021-12-25 21:15:28 +09:00
}