snow/storage/embeds.go
2024-05-29 00:30:33 -07:00

49 lines
740 B
Go

package storage
import (
"embed"
"encoding/json"
"os"
"strings"
)
var (
//go:embed mem/*
Assets embed.FS
)
type snowFS struct {
embed.FS
}
func Asset(file string) (*[]byte) {
data, err := Assets.ReadFile("mem/" + strings.ToLower(file))
if err != nil {
return nil
}
return &data
}
func HttpAsset[T interface{}](file string) (*T) {
// client := http.Client{}
// resp, err := client.Get("https://raw.githubusercontent.com/ectrc/ectrc/main/" + file)
// if err != nil {
// return nil
// }
data, err := os.ReadFile("./data/" + file)
// data, err := io.ReadAll(resp.Body)
if err != nil {
return nil
}
var assetData T
err = json.Unmarshal(data, &assetData)
if err != nil {
return nil
}
return &assetData
}