-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmain.go
51 lines (43 loc) · 958 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"log"
"math/rand"
"os"
"time"
"golang.org/x/net/context"
)
var (
serverMode bool
debugMode bool
host string
password string
username string
)
func init() {
flag.BoolVar(&serverMode, "s", false, "run as the server")
flag.BoolVar(&debugMode, "v", false, "enable debug logging")
flag.StringVar(&host, "h", "0.0.0.0:6262", "the chat server's host")
flag.StringVar(&password, "p", "", "the chat server's password")
flag.StringVar(&username, "n", "", "the username for the client")
flag.Parse()
}
func init() {
rand.Seed(time.Now().UnixNano())
log.SetFlags(0)
}
func main() {
ctx := SignalContext(context.Background())
var err error
if serverMode {
DebugLogf("server mode")
err = Server(host, password).Run(ctx)
} else {
DebugLogf("client mode")
err = Client(host, password, username).Run(ctx)
}
if err != nil {
MessageLog(time.Now(), "<<Process>>", err.Error())
os.Exit(1)
}
}