Commit 6e04c8cf authored by StreatCodes's avatar StreatCodes
Browse files

Include slug in listDashboards

parent b213f50a
......@@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path"
"path/filepath"
"regexp"
"strings"
......@@ -18,12 +19,15 @@ import (
//Dashboard contains all information to render a dashboard
type Dashboard struct {
Title string `json:"title"`
Slug string `json:"slug"`
Background string `json:"background"`
Tags []string `json:"tags"`
Elements []Element `json:"elements"`
}
//Element contains any service/host information needed
//This is an incomplete representation of the Element
//options arn't included
type Element struct {
Type string `json:"type"`
Title string `json:"title"`
......@@ -58,6 +62,10 @@ func arrayContains(array []string, value string) bool {
return false
}
func slugFromFileName(fileName string) string {
return strings.TrimSuffix(fileName, filepath.Ext(fileName))
}
func handleListDashboards(w http.ResponseWriter, r *http.Request) {
files, err := ioutil.ReadDir("dashboards")
if err != nil {
......@@ -85,10 +93,10 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) {
continue
}
tags := dashboard.Tags
dashboard.Slug = slugFromFileName(f.Name())
if tagParam != "" {
if arrayContains(tags, tagParam) {
if arrayContains(dashboard.Tags, tagParam) {
dashboards = append(dashboards, dashboard)
}
} else {
......
Markdown is supported
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