Skip to content

Commit

Permalink
updated explorer_url table
Browse files Browse the repository at this point in the history
  • Loading branch information
ashi31 committed Sep 13, 2024
1 parent 748c256 commit fd6e983
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions core/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ type ExplorerResponse struct {
}

type ExplorerURL struct {
URL string `gorm:"column:url;primaryKey" json:"ExplorerURL"`
Port int `gorm:"column:port" json:"Explorerport"`
URL string `gorm:"column:url;primaryKey" json:"ExplorerURL"`
Port int `gorm:"column:port" json:"Explorerport"`
Protocol string `gorm:"column:protocol" json:"explorer_protocol"`
}

func (c *Core) InitRubixExplorer() error {
Expand All @@ -91,7 +92,7 @@ func (c *Core) InitRubixExplorer() error {

err = c.s.Read(ExplorerURLTable, &ExplorerURL{}, "url=?", url)
if err != nil {
err = c.s.Write(ExplorerURLTable, &ExplorerURL{URL: url, Port: 443})
err = c.s.Write(ExplorerURLTable, &ExplorerURL{URL: url, Port: 443, Protocol: "https"})
}

if err != nil {
Expand Down Expand Up @@ -213,14 +214,20 @@ func (c *Core) AddExplorer(links []string) error {
var eurl []ExplorerURL

for _, url := range links {
var protocol string
if strings.HasPrefix(url, "https") {
protocol = "https"
url = strings.TrimPrefix(url, "https://")
} else if strings.HasPrefix(url, "http") {
protocol = "http"
url = strings.TrimPrefix(url, "http://")
} else {
protocol = "https"
}
eur := ExplorerURL{
URL: url,
Port: 0,
URL: url,
Port: 0,
Protocol: protocol,
}
eurl = append(eurl, eur)
}
Expand Down Expand Up @@ -266,7 +273,7 @@ func (ec *ExplorerClient) GetAllExplorer() ([]string, error) {
return nil, err
}
for _, url := range eurl {
urls = append(urls, fmt.Sprintf("https://%s", url.URL))
urls = append(urls, fmt.Sprintf("%s://%s", url.Protocol, url.URL))
}
return urls, nil
}

0 comments on commit fd6e983

Please sign in to comment.