diff --git a/adapter.go b/adapter.go index ff6a6edb..cfe3351f 100644 --- a/adapter.go +++ b/adapter.go @@ -6,11 +6,6 @@ import ( "sync" ) -const ( - NoRepoUrl = "" - GithubRepoUrl = "https://raw.githubusercontent.com/GoFarsi/assets/main" -) - type logoPathPattern func(path string) string // adaptLogoPath will format all logo paths of chains and assets by using specific pattern diff --git a/asset.go b/asset.go index cc39f668..329a7ea4 100644 --- a/asset.go +++ b/asset.go @@ -3,6 +3,8 @@ package assets import ( "github.com/GoFarsi/assets/entity" "golang.org/x/exp/maps" + "io" + "net/http" ) type AssetRepo struct { @@ -19,7 +21,19 @@ type Option struct { } func New(repoAddress string) *AssetRepo { - chains := parseAssetsByteToArray() + + client := http.Client{} + resp, err := client.Get(YamlAddress) + if err != nil { + return nil + } + defer resp.Body.Close() + assetsByte, err := io.ReadAll(resp.Body) + if err != nil { + return nil + } + + chains := parseAssetsByteToArray(assetsByte) asset := &AssetRepo{Chains: chains} switch repoAddress { diff --git a/const.go b/const.go new file mode 100644 index 00000000..cbf594a9 --- /dev/null +++ b/const.go @@ -0,0 +1,9 @@ +package assets + +const ( + YamlAddress = "https://raw.githubusercontent.com/GoFarsi/assets/main/resources/assets.yaml" + + // images or other resources repo + NoRepoUrl = "" + GithubRepoUrl = "https://raw.githubusercontent.com/GoFarsi/assets/main" +) diff --git a/parser.go b/parser.go index 0f9bd256..5295ed29 100644 --- a/parser.go +++ b/parser.go @@ -6,11 +6,8 @@ import ( "gopkg.in/yaml.v3" ) -//go:embed resources/assets.yaml -var assetsByte []byte - // parseAssetsByteToArray parse the byte contents of yaml file to array of entity.Chain -func parseAssetsByteToArray() (chains map[string]*entity.Chain) { +func parseAssetsByteToArray(assetsByte []byte) (chains map[string]*entity.Chain) { _ = yaml.Unmarshal(assetsByte, &chains) return chains }