2023-11-08 22:09:08 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2024-02-11 00:27:08 +00:00
|
|
|
"encoding/json"
|
2023-12-10 23:54:31 +00:00
|
|
|
"io"
|
|
|
|
"net/http"
|
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) {
|
2023-12-10 23:54:31 +00:00
|
|
|
client := http.Client{}
|
|
|
|
|
|
|
|
resp, err := client.Get("https://raw.githubusercontent.com/ectrc/ectrc/main/" + file)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := io.ReadAll(resp.Body)
|
|
|
|
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
|
|
|
}
|