chore: unify naming for node related types
This commit is contained in:
parent
b8cde30581
commit
6b170e4c5a
12 changed files with 72 additions and 53 deletions
|
|
@ -3,6 +3,7 @@ package config
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -28,29 +29,34 @@ func (l *LogLevel) UnmarshalText(data []byte) error {
|
|||
}
|
||||
|
||||
type NodeConfig struct {
|
||||
Hostname string `toml:"hostname"`
|
||||
Endpoint string `toml:"endpoint"`
|
||||
Hostname string `toml:"hostname"`
|
||||
Address string `toml:"address"`
|
||||
Port int `toml:"port"`
|
||||
|
||||
KeepaliveInterval int `toml:"keepalive_interval"`
|
||||
LogLevel LogLevel `toml:"log_level"`
|
||||
|
||||
BootstrapMaster string `toml:"bootstrap_master"`
|
||||
ListenOn string `toml:"listen_on"`
|
||||
Port int `toml:"port"`
|
||||
}
|
||||
|
||||
func (c NodeConfig) Validate() error {
|
||||
if c.Address == "" {
|
||||
return errors.New("missing address")
|
||||
}
|
||||
|
||||
if c.Hostname == "" {
|
||||
return errors.New("missing hostname")
|
||||
}
|
||||
|
||||
if c.Endpoint == "" {
|
||||
return errors.New("missing endpoint")
|
||||
}
|
||||
|
||||
if c.KeepaliveInterval < 1 && c.KeepaliveInterval != -1 {
|
||||
return errors.New("invalid keepalive_interval")
|
||||
}
|
||||
|
||||
if net.ParseIP(c.ListenOn) == nil {
|
||||
return errors.New("invalid listen_on")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -59,8 +65,8 @@ func (c *NodeConfig) Merge(other NodeConfig) {
|
|||
c.Hostname = other.Hostname
|
||||
}
|
||||
|
||||
if other.Endpoint != "" {
|
||||
c.Endpoint = other.Endpoint
|
||||
if other.Address != "" {
|
||||
c.Address = other.Address
|
||||
}
|
||||
|
||||
if other.BootstrapMaster != "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue