Skip to content

Commit

Permalink
refactor: remove embed yaml resource and reading by hhtp request
Browse files Browse the repository at this point in the history
  • Loading branch information
mj committed May 18, 2023
1 parent 5979ea1 commit 5426f3a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
5 changes: 0 additions & 5 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package assets
import (
"github.com/GoFarsi/assets/entity"
"golang.org/x/exp/maps"
"io"
"net/http"
)

type AssetRepo struct {
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions const.go
Original file line number Diff line number Diff line change
@@ -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"
)
5 changes: 1 addition & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5426f3a

Please sign in to comment.