snow/storage/embeds.go

49 lines
740 B
Go
Raw Normal View History

2023-11-08 22:09:08 +00:00
package storage
import (
"embed"
"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
)
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
}
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
}
var assetData T
err = json.Unmarshal(data, &assetData)
if err != nil {
return nil
}
return &assetData
2023-11-08 22:09:08 +00:00
}