Cleanup consul/config

This commit is contained in:
Frank Schroeder 2017-05-03 21:02:01 +02:00 committed by Frank Schröder
parent 10acfb7682
commit 42c4265901
3 changed files with 21 additions and 21 deletions

View File

@ -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
}

View File

@ -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 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 != "" {
}
if c.ACLToken != "" {
return c.ACLToken
} else {
}
return ""
}
}

View File

@ -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
}