libnmdc: add default protocol/port if not present

This commit is contained in:
mappu 2016-04-02 13:49:24 +13:00
parent 2c34fe7fcb
commit 83792a4241

View File

@ -16,14 +16,31 @@ type HubEventType int
type HubAddress string
func (this *HubAddress) parse() url.URL {
parsed, err := url.Parse(strings.ToLower(string(*this)))
if err != nil || len(parsed.Host) == 0 {
parsed = &url.URL{
Scheme: "nmdc",
Host: string(*this),
}
}
// Add default port if not specified
if !strings.ContainsRune(parsed.Host, ':') {
parsed.Host = parsed.Host + ":411"
}
return *parsed
}
func (this *HubAddress) IsSecure() bool {
parsed, _ := url.Parse(strings.ToLower(string(*this)))
parsed := this.parse()
return parsed.Scheme == "nmdcs" || parsed.Scheme == "dchubs"
}
func (this *HubAddress) GetHostOnly() string {
parsed, _ := url.Parse(strings.ToLower(string(*this)))
return parsed.Host
return this.parse().Host
}
const (