split off HubAddress struct
This commit is contained in:
parent
dea4f996f9
commit
f350afa0fe
35
HubAddress.go
Normal file
35
HubAddress.go
Normal file
@ -0,0 +1,35 @@
|
||||
package libnmdc
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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 := this.parse()
|
||||
|
||||
return parsed.Scheme == "nmdcs" || parsed.Scheme == "dchubs"
|
||||
}
|
||||
|
||||
func (this *HubAddress) GetHostOnly() string {
|
||||
return this.parse().Host
|
||||
}
|
30
libnmdc.go
30
libnmdc.go
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -21,35 +20,6 @@ const (
|
||||
type ConnectionState int
|
||||
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 := this.parse()
|
||||
|
||||
return parsed.Scheme == "nmdcs" || parsed.Scheme == "dchubs"
|
||||
}
|
||||
|
||||
func (this *HubAddress) GetHostOnly() string {
|
||||
return this.parse().Host
|
||||
}
|
||||
|
||||
const (
|
||||
CONNECTIONSTATE_DISCONNECTED = 1
|
||||
CONNECTIONSTATE_CONNECTING = 2 // Handshake in progress
|
||||
|
Loading…
Reference in New Issue
Block a user