forked from couchbaselabs/showfast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
115 lines (91 loc) · 3.06 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
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/gorilla/mux"
log "gopkg.in/inconshreveable/log15.v2"
)
const (
address = "0.0.0.0:8000"
)
var (
dataSource DataSource
cbHost, cbPass string
)
func home(rw http.ResponseWriter, r *http.Request) {
content, _ := ioutil.ReadFile("app/index.html")
rw.Write(content)
}
func admin(rw http.ResponseWriter, r *http.Request) {
content, _ := ioutil.ReadFile("app/admin.html")
rw.Write(content)
}
func release(rw http.ResponseWriter, r *http.Request) {
content, _ := ioutil.ReadFile("app/release.html")
rw.Write(content)
}
func feed(rw http.ResponseWriter, r *http.Request) {
content, _ := ioutil.ReadFile("app/feed.html")
rw.Write(content)
}
func allRuns(rw http.ResponseWriter, r *http.Request) {
metric := r.URL.Query()["metric"][0]
build := r.URL.Query()["build"][0]
writeJSON(rw, dataSource.getAllRuns(metric, build))
}
func getComparison(rw http.ResponseWriter, r *http.Request) {
baseline := r.URL.Query()["baseline"][0]
target := r.URL.Query()["target"][0]
writeJSON(rw, dataSource.getComparison(baseline, target))
}
func deleteBenchmark(rw http.ResponseWriter, r *http.Request) {
var params struct {
ID string `json:"id"`
}
if err := readJSON(r, ¶ms); err == nil {
dataSource.deleteBenchmark(params.ID)
}
}
func reverseObsolete(rw http.ResponseWriter, r *http.Request) {
var params struct {
ID string `json:"id"`
}
if err := readJSON(r, ¶ms); err == nil {
dataSource.reverseObsolete(params.ID)
}
}
func init() {
cbHost = os.Getenv("CB_HOST")
cbPass = os.Getenv("CB_PASS")
if cbHost == "" || cbPass == "" {
log.Error("Missing Couchbase Server settings.")
os.Exit(1)
}
}
func main() {
dataSource = DataSource{cbHost, cbPass}
router := mux.NewRouter()
router.HandleFunc("/", home).Methods("GET")
router.HandleFunc("/admin", admin).Methods("GET")
router.HandleFunc("/feed", feed).Methods("GET")
router.HandleFunc("/release", release).Methods("GET")
router.HandleFunc("/all_metrics", dataSource.getAllMetrics).Methods("GET")
router.HandleFunc("/all_clusters", dataSource.getAllClusters).Methods("GET")
router.HandleFunc("/all_timelines", dataSource.getAllTimelines).Methods("GET")
router.HandleFunc("/all_benchmarks", dataSource.getAllBenchmarks).Methods("GET")
router.HandleFunc("/all_releases", dataSource.getAllReleases).Methods("GET")
router.HandleFunc("/all_feed_records", dataSource.getAllFeedRecords).Methods("GET")
router.HandleFunc("/all_runs", allRuns).Methods("GET")
router.HandleFunc("/get_comparison", getComparison).Methods("GET")
router.HandleFunc("/delete", deleteBenchmark).Methods("POST")
router.HandleFunc("/reverse_obsolete", reverseObsolete).Methods("POST")
router.PathPrefix("/css").Handler(http.FileServer(http.Dir("./app")))
router.PathPrefix("/js").Handler(http.FileServer(http.Dir("./app")))
router.PathPrefix("/partials").Handler(http.FileServer(http.Dir("./app")))
http.Handle("/", router)
banner := fmt.Sprintf("\n\t.:: Serving http://%s/ ::.\n", address)
fmt.Println(banner)
http.ListenAndServe(address, accessLog(http.DefaultServeMux))
}