feat(api): extra fields with parsed filter data in the API response

This commit is contained in:
Łukasz Mierzwa
2018-07-19 23:38:11 +02:00
parent 8f733e0694
commit 4fe19c3d73
3 changed files with 24 additions and 0 deletions
+18
View File
@@ -15,6 +15,9 @@ type FilterT interface {
GetRawText() string
GetHits() int
GetIsValid() bool
GetName() string
GetMatcher() string
GetValue() string
}
type alertFilter struct {
@@ -49,6 +52,21 @@ func (filter *alertFilter) GetIsValid() bool {
return filter.IsValid
}
func (filter *alertFilter) GetName() string {
return filter.Matched
}
func (filter *alertFilter) GetMatcher() string {
if filter.Matcher == nil {
return ""
}
return filter.Matcher.GetOperator()
}
func (filter *alertFilter) GetValue() string {
return fmt.Sprintf("%s", filter.Value)
}
type newFilterFactory func() FilterT
// NewFilter creates new filter object from filter expression like "key=value"
+3
View File
@@ -3,6 +3,9 @@ package models
// Filter holds returned data on any filter passed by the user as part of the query
type Filter struct {
Text string `json:"text"`
Name string `json:"name"`
Matcher string `json:"matcher"`
Value string `json:"value"`
Hits int `json:"hits"`
IsValid bool `json:"isValid"`
}
+3
View File
@@ -149,6 +149,9 @@ func alerts(c *gin.Context) {
for _, filter := range matchFilters {
af := models.Filter{
Text: filter.GetRawText(),
Name: filter.GetName(),
Matcher: filter.GetMatcher(),
Value: filter.GetValue(),
Hits: filter.GetHits(),
IsValid: filter.GetIsValid(),
}