70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
type HostConfig struct {
|
|
Domain string `toml:"domain"`
|
|
IpAddress string `toml:"ip"`
|
|
LocalAddress string `toml:"local_address"`
|
|
InternalEntrypoint string `toml:"internal_entrypoint"`
|
|
ExternalEntrypoint string `toml:"external_entrypoint"`
|
|
baseRoleConfig
|
|
}
|
|
|
|
func (c HostConfig) Validate() error {
|
|
if c.Domain == "" {
|
|
return errors.New("missing domain")
|
|
}
|
|
|
|
if c.IpAddress == "" {
|
|
return errors.New("missing ip")
|
|
}
|
|
|
|
if net.ParseIP(c.IpAddress) == nil {
|
|
return fmt.Errorf("invalid ip: %q", c.IpAddress)
|
|
}
|
|
|
|
if c.LocalAddress == "" {
|
|
return errors.New("missing local address")
|
|
}
|
|
|
|
if c.InternalEntrypoint == "" {
|
|
return errors.New("missing internal entrypoint")
|
|
}
|
|
|
|
if c.ExternalEntrypoint == "" {
|
|
return errors.New("missing external entrypoint")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *HostConfig) Merge(other HostConfig) {
|
|
if other.set {
|
|
c.set = other.set
|
|
}
|
|
|
|
if other.Domain != "" {
|
|
c.Domain = other.Domain
|
|
}
|
|
|
|
if other.IpAddress != "" {
|
|
c.IpAddress = other.IpAddress
|
|
}
|
|
|
|
if other.LocalAddress != "" {
|
|
c.LocalAddress = other.LocalAddress
|
|
}
|
|
|
|
if other.InternalEntrypoint != "" {
|
|
c.InternalEntrypoint = other.InternalEntrypoint
|
|
}
|
|
|
|
if other.ExternalEntrypoint != "" {
|
|
c.ExternalEntrypoint = other.ExternalEntrypoint
|
|
}
|
|
}
|