1
0
Fork 0

chore: unify naming for node related types

This commit is contained in:
Arthur K. 2026-01-18 01:08:52 +03:00
parent bbee40ec98
commit 4d44012d06
Signed by: wzray
GPG key ID: B97F30FDC4636357
12 changed files with 72 additions and 53 deletions

View file

@ -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 != "" {