-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
61 lines (46 loc) · 1.14 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
package main
import (
"bufio"
"fmt"
"os"
"time"
"./ddp"
)
func application(ddpClient *ddp.DDPClient) {
fmt.Println("")
fmt.Println("-----------------")
fmt.Println("Hey, i am running")
ddpClient.Logout()
}
func entryPoint(ddpClient *ddp.DDPClient, readyChan chan bool) {
// Wait a second, to init
time.Sleep(time.Second)
initTimer := time.NewTimer(time.Second * 10)
initTimerChan := initTimer.C
for {
select {
case <-initTimerChan:
ddp.ClientExit("I've waited enough for initialization, exiting...")
case <-readyChan:
initTimer.Stop()
fmt.Println("Done init")
go application(ddpClient)
}
}
}
func main() {
if len(os.Args) != 4 {
fmt.Println("Usage: go run main.go hostname port path(e.g. 'websocket')")
os.Exit(1)
}
fmt.Println("--> Hit any key to terminate <--")
// last argument is used to enable login
ddpClient := ddp.NewDDPClient(os.Args[1], os.Args[2], os.Args[3], true)
go ddpClient.ListenRead()
readyChan := make(chan bool)
go entryPoint(ddpClient, readyChan)
ddpClient.ConnectUsingSaneDefaults(readyChan)
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
fmt.Println(text)
}