-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.06 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 (
"log"
"sync"
"github.com/PI2-Irri/goberry/api"
"github.com/PI2-Irri/goberry/common"
"github.com/PI2-Irri/goberry/controller"
"github.com/PI2-Irri/goberry/measurement"
"github.com/PI2-Irri/goberry/socket"
)
func init() {
log.SetFlags(log.Ltime)
}
func main() {
log.Println("Starting GoBerry")
common.SetFlags()
// Creates the API object and logs in
api := api.Instance()
api.SignUp()
api.Login()
// Creates the Controller
ctr := controller.Instance()
// Creates TCP server socket
serverSocket := socket.CreateServer()
// Runs it in another thread
var wg sync.WaitGroup
wg.Add(1)
go func() {
serverSocket.AcceptConnections()
wg.Done()
}()
defer close(measurement.Queue)
// Creates a TCP client socket
clientSocket := socket.CreateClient()
// Runs client thread
wg.Add(1)
go func() {
clientSocket.Start()
wg.Done()
}()
defer close(socket.ClientQueue)
// Starts the HTTP Polling
wg.Add(1)
go func() {
ctr.Poll()
wg.Done()
}()
// Wait for all threads to be finished
log.Println("Everything started")
wg.Wait()
}