-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (58 loc) · 2.04 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
72
73
74
package main
import (
"net"
"net/http"
"dkfbasel.ch/orca/collaboration/src/internal/environment"
"dkfbasel.ch/orca/collaboration/src/internal/rpc"
"dkfbasel.ch/orca/collaboration/src/repository"
"dkfbasel.ch/orca/collaboration/src/websocket"
"dkfbasel.ch/orca/pkg/logger"
)
func main() {
// ensure thata the logger is flushed when the application is terminated
defer logger.Sync()
// load the application configuration
config, err := environment.LoadConfiguration("profiles")
if err != nil {
logger.FatalError("startup aborted, incomplete configuration", err)
}
// initialize service struct
srv := environment.Services{}
// establish a connection to the redis instance
srv.Redis, err = repository.NewRedisClient(config.Redis.Host, config.Redis.Password)
if err != nil {
logger.FatalError("startup aborted. could not initialize redis connection", err)
}
defer srv.Redis.Close()
// establish a new postgres connection
srv.Postgres, err = repository.NewPostgresClient(config.Postgres)
if err != nil {
logger.FatalError("startup aborted. could not initialize postgres connection", err)
}
defer srv.Postgres.Close()
// initialize connection to the process service
srv.Process, err = rpc.NewProcessClient(config.Process.Address)
if err != nil {
logger.FatalError("startup aborted. could not initialize process service", err)
}
// initialize connection to the image service
srv.Image, err = rpc.NewImageClient(config.Image.Address)
if err != nil {
logger.FatalError("startup aborted. could not initialize image service", err)
}
// start a tcp listener on the given port
listener, err := net.Listen("tcp", config.Websocket.Host)
if err != nil {
logger.FatalError("failed to start tcp server", err)
}
defer listener.Close()
// define the websocket server
wsServer := websocket.NewServer(&srv)
defer wsServer.Close() // nolint:errcheck
logger.Info("starting server")
// start the websocket server
err = wsServer.Serve(listener)
if err != http.ErrServerClosed {
logger.FatalError("failed to listen and serve", err)
}
}