From 1fb85fd0e32594ee7dca339ee7564c05d401d410 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Fri, 4 Dec 2015 15:38:13 -0700 Subject: [PATCH] main: merge host and addr --- cmd/pilosa/config.go | 20 +++++++++----------- cmd/pilosa/main.go | 11 ++++++++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cmd/pilosa/config.go b/cmd/pilosa/config.go index ba57ef2b2..e63d75443 100644 --- a/cmd/pilosa/config.go +++ b/cmd/pilosa/config.go @@ -7,23 +7,17 @@ import ( ) const ( - // DefaultHost is the default hostname to use. - DefaultHost = "localhost" - - // DefaultAddr is the default HTTP address to use. - DefaultAddr = ":15000" + // DefaultHost is the default hostname and port to use. + DefaultHost = "localhost:15000" ) // Config represents the configuration for the command. type Config struct { Host string `toml:"host"` - Addr string `toml:"addr"` Cluster struct { - ReplicaN int `toml:"replicas"` - Nodes []struct { - Host string `toml:"host"` - } `toml:"nodes"` + ReplicaN int `toml:"replicas"` + Nodes []*ConfigNode `toml:"nodes"` } `toml:"cluster"` Plugins struct { @@ -31,13 +25,17 @@ type Config struct { } `toml:"plugins"` } +type ConfigNode struct { + Host string `toml:"host"` +} + // NewConfig returns an instance of Config with default options. func NewConfig() *Config { c := &Config{ Host: DefaultHost, - Addr: DefaultAddr, } c.Cluster.ReplicaN = pilosa.DefaultReplicaN + c.Cluster.Nodes = []*ConfigNode{{Host: DefaultHost}} return c } diff --git a/cmd/pilosa/main.go b/cmd/pilosa/main.go index d67326c64..2ae81d95d 100644 --- a/cmd/pilosa/main.go +++ b/cmd/pilosa/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "flag" "fmt" "io" @@ -86,6 +87,14 @@ func (m *Main) Run(args ...string) error { fmt.Fprintf(m.Stdout, "Using config: %s\n", m.ConfigPath) } + // Require a port in the hostname. + _, addr, err := net.SplitHostPort(m.Config.Host) + if err != nil { + return err + } else if addr == "" { + return errors.New("port must be specified in config host") + } + // Set up profiling. if m.CPUProfile != "" { f, err := os.Create(m.CPUProfile) @@ -114,7 +123,7 @@ func (m *Main) Run(args ...string) error { h.LogOutput = m.Stderr // Open HTTP listener. - ln, err := net.Listen("tcp", m.Config.Addr) + ln, err := net.Listen("tcp", ":"+addr) if err != nil { return err }