Skip to content

Commit a28d71c

Browse files
committed
Add option to bind to 0.0.0.0
1 parent 05a7efd commit a28d71c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type args struct {
5555
Admin string `arg:"-a" default:"8bit" help:"admin user nick, allows access to /sudo" placeholder:"NICK"`
5656
DB string `arg:"-d" default:"./go-chat.db" help:"sqlite database to store server data" placeholder:"FILE"`
5757
HistLen uint `arg:"-l" default:"10" help:"set message history size" placeholder:"N"`
58+
Bind bool `arg:"-b" default:"false" help:"bind to 0.0.0.0 instead of 127.0.0.1 (localhost)"`
5859
Port uint `arg:"positional" default:"0" help:"port to listen on, random available port if not set"`
5960
NickMap *string `arg:"-n" help:"path to nick:pass JSON file" placeholder:"FILE"`
6061
}
@@ -81,7 +82,12 @@ func main() {
8182
log.Fatal(err)
8283
}
8384

84-
err = run("localhost:"+fmt.Sprint(args.Port), nickMap, args.Admin, int(args.HistLen), log, args.DB)
85+
addr := "localhost:"
86+
if args.Bind {
87+
addr = "0.0.0.0:"
88+
}
89+
90+
err = run(addr+fmt.Sprint(args.Port), nickMap, args.Admin, int(args.HistLen), log, args.DB)
8591
if err != nil {
8692
log.Fatal(err)
8793
}

0 commit comments

Comments
 (0)