This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
71 lines (57 loc) · 1.67 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"log"
"os"
"time"
"github.com/qbeon/webwire-go/examples/chatroom/shared"
wwrclt "github.com/qbeon/webwire-go/client"
)
// ChatroomClient implements the wwrclt.Implementation interface
type ChatroomClient struct {
connection *wwrclt.Client
}
// NewChatroomClient constructs and returns a new chatroom client instance
func NewChatroomClient(serverAddr string) *ChatroomClient {
newChatroomClient := &ChatroomClient{}
// Initialize connection
newChatroomClient.connection = wwrclt.NewClient(
serverAddr,
newChatroomClient,
wwrclt.Options{
DefaultRequestTimeout: 10 * time.Second,
// Default timeout for timed requests
ReconnectionInterval: 2 * time.Second,
// Session info parser function must override the default one
// for the session info object to be typed as shared.SessionInfo
SessionInfoParser: shared.SessionInfoParser,
// Custom loggers
WarnLog: log.New(
os.Stdout,
"WARN: ",
log.Ldate|log.Ltime|log.Lshortfile,
),
ErrorLog: log.New(
os.Stderr,
"ERR: ",
log.Ldate|log.Ltime|log.Lshortfile,
),
},
)
return newChatroomClient
}
var serverAddr = flag.String("addr", ":9090", "server address")
var password = flag.String("pass", "", "password")
var username = flag.String("name", "", "username")
func main() {
// Parse command line arguments
flag.Parse()
// Create a new chatroom client instance including its connection
chatroomClient := NewChatroomClient(*serverAddr)
// Authenticate if credentials are already provided from the CLI
if *username != "" && *password != "" {
chatroomClient.Authenticate(*username, *password)
}
// Start the main loop
chatroomClient.Start()
}