add TLS support
Anthony DeDominic adedomin@gmail.com
Sun, 16 Jan 2022 12:23:17 -0500
1 files changed,
18 insertions(+),
7 deletions(-)
jump to
M
main.go
→
main.go
@@ -1,6 +1,7 @@
package main import ( + "crypto/tls" "errors" "log" "net"@@ -67,12 +68,6 @@ }
} func main() { - conn, err := net.Dial("tcp", config.C.Host) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - ircConfig := irc.ClientConfig{ Nick: config.C.Nick, Pass: config.C.Pass,@@ -81,13 +76,29 @@ 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() - client := irc.NewClient(conn, ircConfig) + 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) + } err = client.Run() if err != nil { log.Fatal(err)