From 42c4265901e36e97b76621ee09c37303f3476e41 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Wed, 3 May 2017 21:02:01 +0200 Subject: [PATCH] Cleanup consul/config --- consul/client.go | 2 +- consul/config.go | 38 +++++++++++++++++++------------------- consul/server.go | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/consul/client.go b/consul/client.go index 78c671289c..7961cd4899 100644 --- a/consul/client.go +++ b/consul/client.go @@ -84,7 +84,7 @@ type Client struct { // configuration, potentially returning an error func NewClient(config *Config) (*Client, error) { // Check the protocol version - if err := config.CheckVersion(); err != nil { + if err := config.CheckProtocolVersion(); err != nil { return nil, err } diff --git a/consul/config.go b/consul/config.go index 576d5c3aa7..cbbb364abc 100644 --- a/consul/config.go +++ b/consul/config.go @@ -17,6 +17,7 @@ import ( const ( DefaultDC = "dc1" + DefaultRPCPort = 8300 DefaultLANSerfPort = 8301 DefaultWANSerfPort = 8302 @@ -31,13 +32,13 @@ const ( ) var ( - DefaultRPCAddr = &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: 8300} -) + DefaultRPCAddr = &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: DefaultRPCPort} -// ProtocolVersionMap is the mapping of Consul protocol versions -// to Serf protocol versions. We mask the Serf protocols using -// our own protocol version. -var protocolVersionMap map[uint8]uint8 + // ProtocolVersionMap is the mapping of Consul protocol versions + // to Serf protocol versions. We mask the Serf protocols using + // our own protocol version. + protocolVersionMap map[uint8]uint8 +) func init() { protocolVersionMap = map[uint8]uint8{ @@ -307,19 +308,18 @@ type Config struct { AutopilotInterval time.Duration } -// CheckVersion is used to check if the ProtocolVersion is valid -func (c *Config) CheckVersion() error { +// CheckProtocolVersion validates the protocol version. +func (c *Config) CheckProtocolVersion() error { if c.ProtocolVersion < ProtocolVersionMin { - return fmt.Errorf("Protocol version '%d' too low. Must be in range: [%d, %d]", - c.ProtocolVersion, ProtocolVersionMin, ProtocolVersionMax) - } else if c.ProtocolVersion > ProtocolVersionMax { - return fmt.Errorf("Protocol version '%d' too high. Must be in range: [%d, %d]", - c.ProtocolVersion, ProtocolVersionMin, ProtocolVersionMax) + return fmt.Errorf("Protocol version '%d' too low. Must be in range: [%d, %d]", c.ProtocolVersion, ProtocolVersionMin, ProtocolVersionMax) + } + if c.ProtocolVersion > ProtocolVersionMax { + return fmt.Errorf("Protocol version '%d' too high. Must be in range: [%d, %d]", c.ProtocolVersion, ProtocolVersionMin, ProtocolVersionMax) } return nil } -// CheckACL is used to sanity check the ACL configuration +// CheckACL validates the ACL configuration. func (c *Config) CheckACL() error { switch c.ACLDefaultPolicy { case "allow": @@ -337,7 +337,7 @@ func (c *Config) CheckACL() error { return nil } -// DefaultConfig is used to return a sane default configuration +// DefaultConfig returns a sane default configuration. func DefaultConfig() *Config { hostname, err := os.Hostname() if err != nil { @@ -453,9 +453,9 @@ func (c *Config) tlsConfig() *tlsutil.Config { func (c *Config) GetTokenForAgent() string { if c.ACLAgentToken != "" { return c.ACLAgentToken - } else if c.ACLToken != "" { - return c.ACLToken - } else { - return "" } + if c.ACLToken != "" { + return c.ACLToken + } + return "" } diff --git a/consul/server.go b/consul/server.go index 92fb81c140..42c149ba6f 100644 --- a/consul/server.go +++ b/consul/server.go @@ -210,7 +210,7 @@ type endpoints struct { // configuration, potentially returning an error func NewServer(config *Config) (*Server, error) { // Check the protocol version. - if err := config.CheckVersion(); err != nil { + if err := config.CheckProtocolVersion(); err != nil { return nil, err }