From 21cf6b6e57b1cd18c26a8a51609f452cab49f482 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Thu, 5 Jul 2018 17:59:18 -0500 Subject: [PATCH] remove URI getters since the fields were exported for serialization --- gossip/gossip.go | 6 +++--- http/client.go | 4 ++-- server/server.go | 12 ++++++------ uri.go | 15 --------------- uri_internal_test.go | 14 +++++++------- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/gossip/gossip.go b/gossip/gossip.go index 28b3ac690..7a11d01d4 100644 --- a/gossip/gossip.go +++ b/gossip/gossip.go @@ -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 diff --git a/http/client.go b/http/client.go index 19bf82815..de6eb89f6 100644 --- a/http/client.go +++ b/http/client.go @@ -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, } diff --git a/server/server.go b/server/server.go index f46f6a64a..401da09e8 100644 --- a/server/server.go +++ b/server/server.go @@ -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 diff --git a/uri.go b/uri.go index e01bf8bcc..8577c8238 100644 --- a/uri.go +++ b/uri.go @@ -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 diff --git a/uri_internal_test.go b/uri_internal_test.go index 2587223f8..3c9631661 100644 --- a/uri_internal_test.go +++ b/uri_internal_test.go @@ -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) } }