forked from couchbaselabs/showfast
/
main.go
105 lines (84 loc) · 2.34 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"github.com/hoisie/web"
)
var pckg_dir string
var data_source DataSource
func home() []byte {
content, _ := ioutil.ReadFile(pckg_dir + "app/index.html")
return content
}
func all_runs(ctx *web.Context) []byte {
metric := ctx.Params["metric"]
build := ctx.Params["build"]
return data_source.GetAllRuns(metric, build)
}
func admin() []byte {
content, _ := ioutil.ReadFile(pckg_dir + "app/admin.html")
return content
}
func release() []byte {
content, _ := ioutil.ReadFile(pckg_dir + "app/release.html")
return content
}
func feed() []byte {
content, _ := ioutil.ReadFile(pckg_dir + "app/feed.html")
return content
}
func get_comparison(ctx *web.Context) []byte {
baseline := ctx.Params["baseline"]
target := ctx.Params["target"]
return data_source.GetComparison(baseline, target)
}
func delete(ctx *web.Context) {
var params struct {
ID string `json:"id"`
}
body, _ := ioutil.ReadAll(ctx.Request.Body)
json.Unmarshal(body, ¶ms)
data_source.DeleteBenchmark(params.ID)
}
func reverse_obsolete(ctx *web.Context) {
var params struct {
ID string `json:"id"`
}
body, _ := ioutil.ReadAll(ctx.Request.Body)
json.Unmarshal(body, ¶ms)
data_source.ReverseObsolete(params.ID)
}
type Config struct {
CouchbaseAddress, BucketPassword, ListenAddress string
}
func main() {
pckg_dir = os.Getenv("GOPATH") + "/src/github.com/couchbaselabs/showfast/"
web.Config.StaticDir = pckg_dir + "app"
config_file, err := ioutil.ReadFile(pckg_dir + "config.json")
if err != nil {
log.Fatal(err)
}
var config Config
err = json.Unmarshal(config_file, &config)
if err != nil {
log.Fatal(err)
}
data_source = DataSource{config.CouchbaseAddress, config.BucketPassword}
web.Get("/", home)
web.Get("/admin", admin)
web.Get("/release", release)
web.Get("/feed", feed)
web.Get("/all_metrics", data_source.GetAllMetrics)
web.Get("/all_clusters", data_source.GetAllClusters)
web.Get("/all_timelines", data_source.GetAllTimelines)
web.Get("/all_benchmarks", data_source.GetAllBenchmarks)
web.Get("/all_runs", all_runs)
web.Get("/all_releases", data_source.GetAllReleases)
web.Get("/all_feed_records", data_source.GetAllFeedRecords)
web.Get("/get_comparison", get_comparison)
web.Post("/delete", delete)
web.Post("/reverse_obsolete", reverse_obsolete)
web.Run(config.ListenAddress)
}