fortune 增加设置底图并加速base64 和下载

This commit is contained in:
fumiama
2021-10-09 12:30:59 +08:00
parent 3faec79371
commit a5d0b8db8e
7 changed files with 550 additions and 79 deletions

21
data/dl.go Normal file
View 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
View 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))
}