Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b16767e9a | |||
| 51575385f6 | |||
| b33dd35bdc | |||
| 6143dd8d3a | |||
| 106c58c5da |
@@ -11,17 +11,13 @@ import (
|
|||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sectionMap = map[string]func(*Config, *basic.Section) error{
|
|
||||||
"global": loadGlobalConfSection,
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadConfSection(out *Config, src *basic.Section) error {
|
func loadConfSection(out *Config, src *basic.Section) error {
|
||||||
h, ok := sectionMap[src.Key]
|
switch src.Key {
|
||||||
if !ok {
|
case "global":
|
||||||
|
return loadGlobalConfSection(out, src)
|
||||||
|
default:
|
||||||
return core.Wrapf(fs.ErrInvalid, "unknown section %q", src.Key)
|
return core.Wrapf(fs.ErrInvalid, "unknown section %q", src.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return h(out, src)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadGlobalConfSection(out *Config, src *basic.Section) error {
|
func loadGlobalConfSection(out *Config, src *basic.Section) error {
|
||||||
@@ -73,19 +69,6 @@ func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error {
|
|||||||
entries, _ := parser.SplitCommaArray(field.Value)
|
entries, _ := parser.SplitCommaArray(field.Value)
|
||||||
cfg.Monitors = append(cfg.Monitors, entries...)
|
cfg.Monitors = append(cfg.Monitors, entries...)
|
||||||
return nil
|
return nil
|
||||||
case "cluster_network":
|
|
||||||
if !core.IsZero(cfg.ClusterNetwork) {
|
|
||||||
err := core.Wrap(fs.ErrInvalid, "fields before the first section")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err := cfg.ClusterNetwork.UnmarshalText([]byte(field.Value))
|
|
||||||
switch {
|
|
||||||
case err != nil:
|
|
||||||
return core.Wrap(err, field.Key)
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ type PeerConfig struct {
|
|||||||
Name string
|
Name string
|
||||||
PublicKey PublicKey
|
PublicKey PublicKey
|
||||||
Endpoint EndpointAddress
|
Endpoint EndpointAddress
|
||||||
AllowedIPs []netip.Prefix
|
AllowedIPs []netip.Prefix `ini:",comma"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EndpointAddress is a host:port pair to reach the Peer
|
// EndpointAddress is a host:port pair to reach the Peer
|
||||||
|
|||||||
@@ -8,20 +8,15 @@ import (
|
|||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sectionHandler func(*Config, *basic.Section) error
|
|
||||||
|
|
||||||
var sectionMap = map[string]func(*Config, *basic.Section) error{
|
|
||||||
"Interface": loadInterfaceConfSection,
|
|
||||||
"Peer": loadPeerConfSection,
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadConfSection(out *Config, src *basic.Section) error {
|
func loadConfSection(out *Config, src *basic.Section) error {
|
||||||
h, ok := sectionMap[src.Key]
|
switch src.Key {
|
||||||
if !ok {
|
case "Interface":
|
||||||
|
return loadInterfaceConfSection(out, src)
|
||||||
|
case "Peer":
|
||||||
|
return loadPeerConfSection(out, src)
|
||||||
|
default:
|
||||||
return core.Wrapf(fs.ErrInvalid, "unknown section %q", src.Key)
|
return core.Wrapf(fs.ErrInvalid, "unknown section %q", src.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return h(out, src)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadInterfaceConfSection(out *Config, src *basic.Section) error {
|
func loadInterfaceConfSection(out *Config, src *basic.Section) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user