use readwritecloser interface type
Anthony DeDominic adedomin@gmail.com
Sun, 16 Jan 2022 13:13:41 -0500
1 files changed,
14 insertions(+),
17 deletions(-)
jump to
M
main.go
→
main.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)