Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
David Kempe
Meerkat
Commits
c0f99ad2
Commit
c0f99ad2
authored
Aug 21, 2020
by
Max Reeves
Browse files
server-side tags function
parent
8d70ca6a
Changes
1
Show whitespace changes
Inline
Side-by-side
dashboard.go
View file @
c0f99ad2
...
...
@@ -19,6 +19,7 @@ import (
type
Dashboard
struct
{
Title
string
`json:"title"`
Background
string
`json:"background"`
Tags
[]
string
`json:"tags"`
Checks
[]
Check
`json:"checks"`
}
...
...
@@ -48,6 +49,15 @@ func titleToSlug(title string) string {
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
)
{
files
,
err
:=
ioutil
.
ReadDir
(
"dashboards"
)
if
err
!=
nil
{
...
...
@@ -56,6 +66,7 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) {
}
var
dashboards
[]
Dashboard
tagParam
:=
r
.
URL
.
Query
()
.
Get
(
"tag"
)
for
_
,
f
:=
range
files
{
if
strings
.
HasSuffix
(
f
.
Name
(),
".json"
)
{
...
...
@@ -74,8 +85,16 @@ func handleListDashboards(w http.ResponseWriter, r *http.Request) {
continue
}
tags
:=
dashboard
.
Tags
if
tagParam
!=
""
{
if
arrayContains
(
tags
,
tagParam
)
{
dashboards
=
append
(
dashboards
,
dashboard
)
}
}
else
{
dashboards
=
append
(
dashboards
,
dashboard
)
}
}
}
enc
:=
json
.
NewEncoder
(
w
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment