Add CLI flags for listening address and hostname

This commit is contained in:
Simon Ser 2020-02-17 16:25:09 +01:00
parent 3c3f218b2b
commit 603bd6bdef
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"log"
"net"
@ -8,7 +9,10 @@ import (
)
func main() {
addr := ":6667"
var addr, hostname string
flag.StringVar(&addr, "addr", ":6667", "listening address")
flag.StringVar(&hostname, "hostname", "localhost", "server hostname")
flag.Parse()
ln, err := net.Listen("tcp", addr)
if err != nil {
@ -17,7 +21,7 @@ func main() {
srv := jounce.NewServer()
// TODO: load from config/DB
srv.Hostname = "localhost"
srv.Hostname = hostname
srv.Upstreams = []jounce.Upstream{{
Addr: "chat.freenode.net:6697",
Nick: "jounce",
@ -26,7 +30,7 @@ func main() {
Channels: []string{"#jounce"},
}}
log.Printf("Server listening on %v", addr)
log.Printf("server listening on %v", addr)
go srv.Run()
log.Fatal(srv.Serve(ln))
}