diff options
author | Robert Gerus <arachnist@i.am-a.cat> | 2015-12-12 12:35:49 +0100 |
---|---|---|
committer | Robert Gerus <arachnist@i.am-a.cat> | 2015-12-12 12:35:49 +0100 |
commit | bc36369497181c4f5165c04bc30a32b55203cca9 (patch) | |
tree | 2267507096c0153bb0ad4f5a757a393477c69c30 | |
parent | 6bc3f2fdd4b18106b0fccd37e5df9303e054bc09 (diff) | |
download | gorepost-bc36369497181c4f5165c04bc30a32b55203cca9.tar.gz gorepost-bc36369497181c4f5165c04bc30a32b55203cca9.tar.bz2 gorepost-bc36369497181c4f5165c04bc30a32b55203cca9.tar.xz gorepost-bc36369497181c4f5165c04bc30a32b55203cca9.zip |
Adjust irc package to changes in config.
-rw-r--r-- | irc/irc.go | 14 | ||||
-rw-r--r-- | irc/irc_test.go | 5 |
2 files changed, 10 insertions, 9 deletions
@@ -12,7 +12,7 @@ import ( "sync" "time" - cfg "github.com/arachnist/gorepost/config" + "github.com/arachnist/gorepost/config" ) const delim byte = '\n' @@ -32,6 +32,7 @@ type Connection struct { quitrecv chan struct{} quitkeeper chan struct{} l sync.Mutex + cfg *config.Config } // Sender sends IRC messages to server and logs their contents. @@ -150,7 +151,7 @@ func (c *Connection) Keeper() { close(c.quitrecv) } c.quitrecv = make(chan struct{}, 1) - servers := cfg.LookupStringSlice(context, "Servers") + servers := c.cfg.LookupStringSlice(context, "Servers") server := servers[rand.Intn(len(servers))] log.Println(c.network, "connecting to", server) @@ -162,12 +163,12 @@ func (c *Connection) Keeper() { log.Println(c.network, "Initializing IRC connection") c.Sender(Message{ Command: "NICK", - Trailing: cfg.LookupString(context, "Nick"), + Trailing: c.cfg.LookupString(context, "Nick"), }) c.Sender(Message{ Command: "USER", - Params: []string{cfg.LookupString(context, "User"), "0", "*"}, - Trailing: cfg.LookupString(context, "RealName"), + Params: []string{c.cfg.LookupString(context, "User"), "0", "*"}, + Trailing: c.cfg.LookupString(context, "RealName"), }) } else { log.Println(c.network, "connection error", err.Error()) @@ -178,7 +179,7 @@ func (c *Connection) Keeper() { } // Setup performs initialization tasks. -func (c *Connection) Setup(dispatcher func(func(Message), Message), network string) { +func (c *Connection) Setup(dispatcher func(func(Message), Message), network string, config *config.Config) { rand.Seed(time.Now().UnixNano()) c.reconnect = make(chan struct{}, 1) @@ -187,6 +188,7 @@ func (c *Connection) Setup(dispatcher func(func(Message), Message), network stri c.Quit = make(chan struct{}, 1) c.network = network c.dispatcher = dispatcher + c.cfg = config c.reconnect <- struct{}{} go c.Keeper() diff --git a/irc/irc_test.go b/irc/irc_test.go index a6cad81..0a5dadf 100644 --- a/irc/irc_test.go +++ b/irc/irc_test.go @@ -17,7 +17,7 @@ import ( "testing" "time" - cfg "github.com/arachnist/gorepost/config" + "github.com/arachnist/gorepost/config" ) var expectedOutput = []Message{ @@ -105,7 +105,7 @@ func TestSetup(t *testing.T) { go fakeServer(t) var conn Connection - conn.Setup(fakeDispatcher, "TestNet") + conn.Setup(fakeDispatcher, "TestNet", config.New(configLookupHelper)) time.Sleep(2 * time.Second) @@ -148,7 +148,6 @@ func configLookupHelper(map[string]string) []string { } func TestMain(m *testing.M) { - cfg.SetFileListBuilder(configLookupHelper) log.SetOutput(ioutil.Discard) os.Exit(m.Run()) } |