58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package nomad
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/hashicorp/raft"
|
|
)
|
|
|
|
// These are the protocol versions that Nomad can understand
|
|
const (
|
|
ProtocolVersionMin uint8 = 1
|
|
ProtocolVersionMax = 1
|
|
)
|
|
|
|
// Config is used to parameterize the server
|
|
type Config struct {
|
|
// Bootstrap mode is used to bring up the first Consul server.
|
|
// It is required so that it can elect a leader without any
|
|
// other nodes being present
|
|
Bootstrap bool
|
|
|
|
// DataDir is the directory to store our state in
|
|
DataDir string
|
|
|
|
// LogOutput is the location to write logs to. If this is not set,
|
|
// logs will go to stderr.
|
|
LogOutput io.Writer
|
|
|
|
// ProtocolVersion is the protocol version to speak. This must be between
|
|
// ProtocolVersionMin and ProtocolVersionMax.
|
|
ProtocolVersion uint8
|
|
|
|
// RaftConfig is the configuration used for Raft in the local DC
|
|
RaftConfig *raft.Config
|
|
}
|
|
|
|
// CheckVersion is used to check if the ProtocolVersion is valid
|
|
func (c *Config) CheckVersion() 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 nil
|
|
}
|
|
|
|
// DefaultConfig returns the default configuration
|
|
func DefaultConfig() *Config {
|
|
c := &Config{
|
|
ProtocolVersion: ProtocolVersionMax,
|
|
RaftConfig: raft.DefaultConfig(),
|
|
}
|
|
return c
|
|
}
|