snow/storage/embeds.go

45 lines
656 B
Go
Raw Normal View History

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