remove URI getters since the fields were exported for serialization

This commit is contained in:
Matt Jaffee 2018-07-05 17:59:18 -05:00
parent b7b46f1d66
commit 21cf6b6e57
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
5 changed files with 18 additions and 33 deletions

View file

@ -146,7 +146,7 @@ func WithLogger(logger *log.Logger) GossipMemberSetOption {
// NewGossipMemberSet returns a new instance of GossipMemberSet based on options.
func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...GossipMemberSetOption) (*GossipMemberSet, error) {
host := api.Node().URI.GetHost()
host := api.Node().URI.Host
g := &GossipMemberSet{
papi: api,
Logger: pilosa.NopLogger,
@ -191,10 +191,10 @@ func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...GossipMemberSetO
conf := memberlist.DefaultWANConfig()
conf.Transport = g.transport.Net
conf.Name = api.Node().ID
conf.BindAddr = api.Node().URI.GetHost()
conf.BindAddr = api.Node().URI.Host
conf.BindPort = port
conf.AdvertisePort = port
conf.AdvertiseAddr = hostToIP(api.Node().URI.GetHost())
conf.AdvertiseAddr = hostToIP(api.Node().URI.Host)
//
conf.TCPTimeout = time.Duration(cfg.StreamTimeout)
conf.SuspicionMult = cfg.SuspicionMult

View file

@ -993,7 +993,7 @@ func pos(rowID, columnID uint64) uint64 {
func uriPathToURL(uri *pilosa.URI, path string) url.URL {
return url.URL{
Scheme: uri.GetScheme(),
Scheme: uri.Scheme,
Host: uri.HostPort(),
Path: path,
}
@ -1001,7 +1001,7 @@ func uriPathToURL(uri *pilosa.URI, path string) url.URL {
func nodePathToURL(node *pilosa.Node, path string) url.URL {
return url.URL{
Scheme: node.URI.GetScheme(),
Scheme: node.URI.Scheme,
Host: node.URI.HostPort(),
Path: path,
}

View file

@ -203,7 +203,7 @@ func (m *Command) SetupServer() error {
// Setup TLS
var TLSConfig *tls.Config
if uri.GetScheme() == "https" {
if uri.Scheme == "https" {
if m.Config.TLS.CertificatePath == "" {
return errors.New("certificate path is required for TLS sockets")
}
@ -236,7 +236,7 @@ func (m *Command) SetupServer() error {
}
// If port is 0, get auto-allocated port from listener
if uri.GetPort() == 0 {
if uri.Port == 0 {
uri.SetPort(uint16(m.ln.Addr().(*net.TCPAddr).Port))
}
@ -311,7 +311,7 @@ func (m *Command) SetupNetworking() error {
}
// get the host portion of addr to use for binding
gossipHost := m.API.Node().URI.GetHost()
gossipHost := m.API.Node().URI.Host
m.gossipTransport, err = gossip.NewTransport(gossipHost, gossipPort, m.logger.Logger())
if err != nil {
return errors.Wrap(err, "getting transport")
@ -368,19 +368,19 @@ func NewStatsClient(name string, host string) (pilosa.StatsClient, error) {
// getListener gets a net.Listener based on the config.
func getListener(uri pilosa.URI, tlsconf *tls.Config) (ln net.Listener, err error) {
// If bind URI has the https scheme, enable TLS
if uri.GetScheme() == "https" && tlsconf != nil {
if uri.Scheme == "https" && tlsconf != nil {
ln, err = tls.Listen("tcp", uri.HostPort(), tlsconf)
if err != nil {
return nil, errors.Wrap(err, "tls.Listener")
}
} else if uri.GetScheme() == "http" {
} else if uri.Scheme == "http" {
// Open HTTP listener to determine port (if specified as :0).
ln, err = net.Listen("tcp", uri.HostPort())
if err != nil {
return nil, errors.Wrap(err, "net.Listen")
}
} else {
return nil, errors.Errorf("unsupported scheme: %s", uri.GetScheme())
return nil, errors.Errorf("unsupported scheme: %s", uri.Scheme)
}
return ln, nil

15
uri.go
View file

@ -82,11 +82,6 @@ func NewURIFromAddress(address string) (*URI, error) {
return parseAddress(address)
}
// GetScheme returns the scheme of this URI.
func (u *URI) GetScheme() string {
return u.Scheme
}
// SetScheme sets the scheme of this URI.
func (u *URI) SetScheme(scheme string) error {
m := schemeRegexp.FindStringSubmatch(scheme)
@ -97,11 +92,6 @@ func (u *URI) SetScheme(scheme string) error {
return nil
}
// GetHost returns the host of this URI.
func (u *URI) GetHost() string {
return u.Host
}
// SetHost sets the host of this URI.
func (u *URI) SetHost(host string) error {
m := hostRegexp.FindStringSubmatch(host)
@ -112,11 +102,6 @@ func (u *URI) SetHost(host string) error {
return nil
}
// GetPort returns the port of this URI.
func (u *URI) GetPort() uint16 {
return u.Port
}
// SetPort sets the port of this URI.
func (u *URI) SetPort(port uint16) {
u.Port = port

View file

@ -83,8 +83,8 @@ func TestSetScheme(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if uri.GetScheme() != target {
t.Fatalf("%s != %s", uri.GetScheme(), target)
if uri.Scheme != target {
t.Fatalf("%s != %s", uri.Scheme, target)
}
}
@ -95,7 +95,7 @@ func TestSetHost(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if uri.GetHost() != target {
if uri.Host != target {
t.Fatalf("%s != %s", uri.Host, target)
}
}
@ -104,7 +104,7 @@ func TestSetPort(t *testing.T) {
uri := DefaultURI()
target := uint16(9999)
uri.SetPort(target)
if uri.GetPort() != target {
if uri.Port != target {
t.Fatalf("%d != %d", uri.Port, target)
}
}
@ -137,13 +137,13 @@ func TestHostPort(t *testing.T) {
}
func compare(t *testing.T, uri *URI, scheme string, host string, port uint16) {
if uri.GetScheme() != scheme {
if uri.Scheme != scheme {
t.Fatalf("Scheme does not match: %s != %s", uri.Scheme, scheme)
}
if uri.GetHost() != host {
if uri.Host != host {
t.Fatalf("Host does not match: %s != %s", uri.Host, host)
}
if uri.GetPort() != port {
if uri.Port != port {
t.Fatalf("Port does not match: %d != %d", uri.Port, port)
}
}