mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-11 17:50:25 +00:00
⚡️✨ fortune 增加设置底图并加速base64 和下载
This commit is contained in:
21
data/dl.go
Normal file
21
data/dl.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func DownloadTo(url, file string) error {
|
||||
resp, err := http.Get(url)
|
||||
if err == nil {
|
||||
var f *os.File
|
||||
f, err = os.Create(file)
|
||||
if err == nil {
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
resp.Body.Close()
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
15
data/mem.go
Normal file
15
data/mem.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package data
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// Str2bytes Fast convert
|
||||
func Str2bytes(s string) []byte {
|
||||
x := (*[2]uintptr)(unsafe.Pointer(&s))
|
||||
h := [3]uintptr{x[0], x[1], x[1]}
|
||||
return *(*[]byte)(unsafe.Pointer(&h))
|
||||
}
|
||||
|
||||
// Bytes2str Fast convert
|
||||
func Bytes2str(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
}
|
||||
Reference in New Issue
Block a user