-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 1.13 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
package main
import (
"KeyForge/config"
"KeyForge/db"
"KeyForge/web"
"flag"
"log"
"net/http"
)
var (
dbLocation = flag.String("db-location", "", "Path to boltDB database")
httpAddress = flag.String("http-address", "127.0.0.1:5000", "Http port and host")
configFile = flag.String("config-file", "sharding.toml", "Config file for static sharding")
shard = flag.String("shard", "", "Name of shard for data")
)
func main() {
flag.Parse()
c, err := config.ParseFile(*configFile)
if err != nil {
log.Fatalf("Error parsing config %q: %v", *configFile, err)
}
shards, err := config.ParseShards(c.Shard, *shard)
if err != nil {
log.Fatalf("Error parsing shards config: %v", err)
}
log.Printf("Shard count is %d, current shard: %d", shards.Count, shards.CurrIdx)
DB, close, err := db.NewDatabase(*dbLocation)
if err != nil {
log.Fatalf("Error creating %q: %v", *dbLocation, err)
}
defer close()
srv := web.NewServer(DB, shards)
http.HandleFunc("/set", srv.SetHandler)
http.HandleFunc("/get", srv.GetHandler)
http.HandleFunc("/purge", srv.DeleteExtraKeysHandler)
log.Fatal(http.ListenAndServe(*httpAddress, nil))
}