Commit c0f99ad2 authored by Max Reeves's avatar Max Reeves
Browse files

server-side tags function

parent 8d70ca6a
...@@ -17,9 +17,10 @@ import ( ...@@ -17,9 +17,10 @@ import (
//Dashboard contains all information to render a dashboard //Dashboard contains all information to render a dashboard
type Dashboard struct { type Dashboard struct {
Title string `json:"title"` Title string `json:"title"`
Background string `json:"background"` Background string `json:"background"`
Checks []Check `json:"checks"` Tags []string `json:"tags"`
Checks []Check `json:"checks"`
} }
//Check contains any service/host information needed //Check contains any service/host information needed
...@@ -48,6 +49,15 @@ func titleToSlug(title string) string { ...@@ -48,6 +49,15 @@ func titleToSlug(title string) string {
return title return title
} }
func arrayContains(array []string, value string) bool {
for _, v := range array {
if v == value {
return true
}
}
return false
}
func handleListDashboards(w http.ResponseWriter, r *http.Request) { func handleListDashboards(w http.ResponseWriter, r *http.Request) {
files, err := ioutil.ReadDir("dashboards") files, err := ioutil.ReadDir("dashboards")
if err != nil { if err != nil {
...@@ -56,6 +66,7 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) { ...@@ -56,6 +66,7 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) {
} }
var dashboards []Dashboard var dashboards []Dashboard
tagParam := r.URL.Query().Get("tag")
for _, f := range files { for _, f := range files {
if strings.HasSuffix(f.Name(), ".json") { if strings.HasSuffix(f.Name(), ".json") {
...@@ -74,7 +85,15 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) { ...@@ -74,7 +85,15 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) {
continue continue
} }
dashboards = append(dashboards, dashboard) tags := dashboard.Tags
if tagParam != "" {
if arrayContains(tags, tagParam) {
dashboards = append(dashboards, dashboard)
}
} else {
dashboards = append(dashboards, dashboard)
}
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment