-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (29 loc) · 1.16 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
package main
import (
"flag"
"strconv"
"github.com/manojks1999/kv-store/httpapi"
"github.com/manojks1999/kv-store/kvstore"
"github.com/manojks1999/kv-store/raftnode"
)
func main() {
id := flag.Uint64("id", 1, "node ID")
clientListenURL := flag.String("listen-client-url", "http://localhost:2379", "client listen URL")
peerListenURL := flag.String("listen-peer-url", "http://localhost:2380", "peer listen URL")
initialCluster := flag.String("initial-cluster", "", "initial cluster configuration")
join := flag.Bool("join", false, "join an existing cluster")
dataDir := flag.String("data-dir", "", "snapshot dir")
keyValueStorePath := flag.String("key-store-dir", "", "key store path")
logDir := dataDir
flag.Parse()
keyValueFile := *keyValueStorePath + "/data-node" + strconv.FormatUint(*id, 10) + ".json"
jsonStore := kvstore.NewJsonStore(keyValueFile)
kvStore := kvstore.NewKeyValueStore(jsonStore)
rn := raftnode.NewRaftNode(*id, kvStore, *initialCluster, *dataDir, *logDir, *join)
apiServer := httpapi.ApiServer{rn}
peerServer := httpapi.PeerServer{rn}
go apiServer.ServeHTTP(*clientListenURL)
go peerServer.ServeHTTP(*peerListenURL)
go rn.Run()
select {}
}