gofmt
Jes Olson j3s@c3f.net
Fri, 17 Feb 2023 19:41:04 -0800
M
agent.go
→
agent.go
@@ -2,7 +2,6 @@ package main
import ( "log" - "os" "sync" "time"@@ -26,38 +25,34 @@ // This is the underlying Serf we are wrapping
serf *serf.Serf // this channel receiving a signal = shutdown - shutdown bool - shutdownCh chan struct{} + shutdown bool + shutdownCh chan struct{} shutdownLock sync.Mutex } -func Create(conf *Config, serfConf *serf.Config) (*Agent) { +func Create(conf *Config, serfConf *serf.Config) *Agent { // Create a channel to listen for events from Serf eventCh := make(chan serf.Event, 64) serfConf.EventCh = eventCh // Setup the agent agent := &Agent{ - conf: conf, - serfConf: serfConf, - eventCh: eventCh, - shutdownCh: make(chan struct{}), + conf: conf, + serfConf: serfConf, + eventCh: eventCh, + shutdownCh: make(chan struct{}), } return agent } -// setupAgent calls Create -func SetupAgent(config *Config) *Agent { +func setupAgent(config *Config) *Agent { bindIP, bindPort, err := config.AddrParts(config.BindAddr) if err != nil { log.Panic(err) } serfConfig := serf.DefaultConfig() - if os.Getenv("CASCADE_BIND") != "" { - config.BindAddr = os.Getenv("CASCADE_BIND") - } serfConfig.MemberlistConfig.BindAddr = bindIP serfConfig.MemberlistConfig.BindPort = bindPort serfConfig.MemberlistConfig.AdvertiseAddr = ""@@ -77,7 +72,6 @@ serfConfig.TombstoneTimeout = 0
serfConfig.BroadcastTimeout = 0 // TODO: what are the implications of true here o_O serfConfig.EnableNameConflictResolution = true - // hardcode DefaultWANConfig because cascade is designed to be // used as a single global system.
M
main.go
→
main.go
@@ -8,11 +8,18 @@ // dns resolver for services
package main -import "log" +import ( + "log" + "os" +) func main() { + c := DefaultConfig() + if os.Getenv("CASCADE_BIND") != "" { + c.BindAddr = os.Getenv("CASCADE_BIND") + } // agent does everything tbh - agent := SetupAgent(DefaultConfig()) + agent := setupAgent(c) log.Println(agent) -// agent.Run() + // agent.Run() }