-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (71 loc) · 2.3 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
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"Recon/controllers"
"Recon/database"
fastp "github.com/Mnwa/fasthttprouter-prometheus"
"github.com/fasthttp/router"
"github.com/valyala/fasthttp"
"log"
"os"
"time"
)
func main() {
addr := os.Getenv("RECON_ADDR")
if addr == "" {
addr = ":8080"
}
go func() {
// save data to disk every second
for {
if database.Client.Len() > 0 {
log.Println("Save data to partitions")
err := database.Client.Sync()
if err != nil {
log.Fatal(err)
}
}
time.Sleep(time.Second)
}
}()
go func() {
// run merge sort every hour
for {
if database.Client.SsTable().Len() > 2 {
log.Println("Merging partitions..")
err := database.Client.SsTable().MergeSort()
if err != nil {
log.Fatal(err)
}
}
time.Sleep(time.Hour)
}
}()
defer database.Client.Sync()
r := router.New()
r.GET("/backup", controllers.GetBackup)
r.POST("/backup", controllers.RestoreBackup)
r.POST("/replication/receiver", controllers.ReceiveMessagesReplication)
// Env based
r.GET("/projects/:project/:type/env", controllers.GetEnv)
r.PUT("/projects/:project/:type/env", controllers.CreateEnv)
r.POST("/projects/:project/:type/env", controllers.UpdateEnv)
r.DELETE("/projects/:project/:type/env", controllers.DeleteEnv)
r.GET("/projects/:project/:type/env/:key", controllers.GetKeyEnv)
r.PUT("/projects/:project/:type/env/:key", controllers.CreateKeyEnv)
r.POST("/projects/:project/:type/env/:key", controllers.UpdateKeyEnv)
r.DELETE("/projects/:project/:type/env/:key", controllers.DeleteKeyEnv)
// Default kv
r.GET("/projects/:project/:type/config", controllers.GetDefault)
r.PUT("/projects/:project/:type/config", controllers.CreateDefault)
r.POST("/projects/:project/:type/config", controllers.UpdateDefault)
r.DELETE("/projects/:project/:type/config", controllers.DeleteDefault)
r.GET("/projects/:project/:type/config/:key", controllers.GetKeyDefault)
r.PUT("/projects/:project/:type/config/:key", controllers.CreateKeyDefault)
r.POST("/projects/:project/:type/config/:key", controllers.UpdateKeyDefault)
r.DELETE("/projects/:project/:type/config/:key", controllers.DeleteKeyDefault)
p := fastp.NewPrometheus("recon")
p.MetricsPath = "/"
fastpHandler := p.WrapHandler(r)
log.Println("Recon started")
log.Fatal(fasthttp.ListenAndServe(addr, fastpHandler))
}