-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (45 loc) · 957 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
52
53
54
55
56
57
package main
import (
"fmt"
clientServices "kv-store/ClientServices"
node "kv-store/Node"
"net/http"
"os"
"strconv"
)
const basePath = "/kv-store"
const (
critical = 0
debug = 1
log = 2
)
/*
* Start the client side API
*/
func main() {
fmt.Println("Starting the distributed key values store...")
// create a node instance
node, nodeStatus := node.NewNode()
errorHandler(nodeStatus, critical)
// Start up the backend services
node.RunBackendSystem()
// register client http endpoints
clientServices.SetupRoutes(basePath, node)
// start listening to client requests
listenAddr := (":" + strconv.Itoa(node.Port))
fmt.Println("Using port:", node.Port)
err := http.ListenAndServe(listenAddr, nil)
errorHandler(err, debug)
}
// Simple error handler
func errorHandler(err error, level int) {
if err != nil {
switch level {
case critical:
fmt.Println(err)
os.Exit(1)
case debug:
fmt.Println(err)
}
}
}