Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer URL Fix #219

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}