mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
main: merge host and addr
This commit is contained in:
parent
ef42e7e74f
commit
1fb85fd0e3
2 changed files with 19 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue