2023-11-08 22:09:08 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2024-02-11 00:27:08 +00:00
|
|
|
"encoding/json"
|
2024-05-29 07:30:33 +00:00
|
|
|
"os"
|
2023-11-08 22:09:08 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-11-09 18:42:28 +00:00
|
|
|
//go:embed mem/*
|
2023-11-08 22:09:08 +00:00
|
|
|
Assets embed.FS
|
|
|
|
)
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
type snowFS struct {
|
|
|
|
embed.FS
|
|
|
|
}
|
|
|
|
|
2023-11-08 22:09:08 +00:00
|
|
|
func Asset(file string) (*[]byte) {
|
2023-11-09 18:42:28 +00:00
|
|
|
data, err := Assets.ReadFile("mem/" + strings.ToLower(file))
|
2023-11-08 22:09:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-12-10 23:54:31 +00:00
|
|
|
return &data
|
|
|
|
}
|
|
|
|
|
2024-02-11 00:27:08 +00:00
|
|
|
func HttpAsset[T interface{}](file string) (*T) {
|
2024-05-29 07:30:33 +00:00
|
|
|
// client := http.Client{}
|
2023-12-10 23:54:31 +00:00
|
|
|
|
2024-05-29 06:57:26 +00:00
|
|
|
// resp, err := client.Get("https://raw.githubusercontent.com/ectrc/ectrc/main/" + file)
|
2024-05-29 07:30:33 +00:00
|
|
|
// if err != nil {
|
|
|
|
// return nil
|
|
|
|
// }
|
2023-12-10 23:54:31 +00:00
|
|
|
|
2024-05-29 07:30:33 +00:00
|
|
|
data, err := os.ReadFile("./data/" + file)
|
|
|
|
// data, err := io.ReadAll(resp.Body)
|
2023-12-10 23:54:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-11 00:27:08 +00:00
|
|
|
var assetData T
|
|
|
|
err = json.Unmarshal(data, &assetData)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &assetData
|
2023-11-08 22:09:08 +00:00
|
|
|
}
|