libnmdc: add default protocol/port if not present
This commit is contained in:
parent
2c34fe7fcb
commit
83792a4241
@ -16,14 +16,31 @@ type HubEventType int
|
|||||||
|
|
||||||
type HubAddress string
|
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 {
|
func (this *HubAddress) IsSecure() bool {
|
||||||
parsed, _ := url.Parse(strings.ToLower(string(*this)))
|
parsed := this.parse()
|
||||||
|
|
||||||
return parsed.Scheme == "nmdcs" || parsed.Scheme == "dchubs"
|
return parsed.Scheme == "nmdcs" || parsed.Scheme == "dchubs"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HubAddress) GetHostOnly() string {
|
func (this *HubAddress) GetHostOnly() string {
|
||||||
parsed, _ := url.Parse(strings.ToLower(string(*this)))
|
return this.parse().Host
|
||||||
return parsed.Host
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user