all repos — paprika @ 2e70eabfec188c44b6aba9721df4331a513d06f8

go rewrite of taigabot

use readwritecloser interface type
Anthony DeDominic adedomin@gmail.com
Sun, 16 Jan 2022 13:13:41 -0500
commit

2e70eabfec188c44b6aba9721df4331a513d06f8

parent

5e7478268e4bce3b6747afe20282d3bd2fe0a7a5

1 files changed, 14 insertions(+), 17 deletions(-)

jump to
M main.gomain.go

@@ -3,6 +3,7 @@

import ( "crypto/tls" "errors" + "io" "log" "net" "strings"

@@ -68,6 +69,18 @@ }

} func main() { + var err error + var conn io.ReadWriteCloser + if !config.C.Tls { + conn, err = net.Dial("tcp", config.C.Host) + } else { + conn, err = tls.Dial("tcp", config.C.Host, nil) + } + if err != nil { + log.Fatal(err) + } + defer conn.Close() + ircConfig := irc.ClientConfig{ Nick: config.C.Nick, Pass: config.C.Pass,

@@ -76,29 +89,13 @@ Name: config.C.Nick,

Handler: irc.HandlerFunc(ircHandler), } - var err error database.DB.DB, err = database.Open() if err != nil { log.Fatal(err) } defer database.DB.Close() - var client *irc.Client - if !config.C.Tls { - conn, err := net.Dial("tcp", config.C.Host) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client = irc.NewClient(conn, ircConfig) - } else { - conn, err := tls.Dial("tcp", config.C.Host, nil) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - client = irc.NewClient(conn, ircConfig) - } + client := irc.NewClient(conn, ircConfig) err = client.Run() if err != nil { log.Fatal(err)