Make type-ids strings

This commit is contained in:
Lou Knauer 2022-05-04 09:18:56 +02:00
parent db099605ec
commit 5f8fc36b5f
2 changed files with 16 additions and 16 deletions

18
api.go
View File

@ -199,9 +199,9 @@ type ApiQuery struct {
Aggregate bool `json:"aggreg"` Aggregate bool `json:"aggreg"`
ScaleFactor Float `json:"scale-by,omitempty"` ScaleFactor Float `json:"scale-by,omitempty"`
Type *string `json:"type,omitempty"` Type *string `json:"type,omitempty"`
TypeIds []int `json:"type-ids,omitempty"` TypeIds []string `json:"type-ids,omitempty"`
SubType *string `json:"subtype,omitempty"` SubType *string `json:"subtype,omitempty"`
SubTypeIds []int `json:"subtype-ids,omitempty"` SubTypeIds []string `json:"subtype-ids,omitempty"`
} }
func handleQuery(rw http.ResponseWriter, r *http.Request) { func handleQuery(rw http.ResponseWriter, r *http.Request) {
@ -235,22 +235,22 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
sel := Selector{{String: req.Cluster}, {String: query.Hostname}} sel := Selector{{String: req.Cluster}, {String: query.Hostname}}
if query.Type != nil { if query.Type != nil {
if len(query.TypeIds) == 1 { if len(query.TypeIds) == 1 {
sel = append(sel, SelectorElement{String: fmt.Sprintf("%s%d", *query.Type, query.TypeIds[0])}) sel = append(sel, SelectorElement{String: *query.Type + query.TypeIds[0]})
} else { } else {
ids := make([]string, len(query.TypeIds)) ids := make([]string, len(query.TypeIds))
for i, id := range query.TypeIds { for i, id := range query.TypeIds {
ids[i] = fmt.Sprintf("%s%d", *query.Type, id) ids[i] = *query.Type + id
} }
sel = append(sel, SelectorElement{Group: ids}) sel = append(sel, SelectorElement{Group: ids})
} }
if query.SubType != nil { if query.SubType != nil {
if len(query.SubTypeIds) == 1 { if len(query.SubTypeIds) == 1 {
sel = append(sel, SelectorElement{String: fmt.Sprintf("%s%d", *query.SubType, query.SubTypeIds[0])}) sel = append(sel, SelectorElement{String: *query.SubType + query.SubTypeIds[0]})
} else { } else {
ids := make([]string, len(query.SubTypeIds)) ids := make([]string, len(query.SubTypeIds))
for i, id := range query.SubTypeIds { for i, id := range query.SubTypeIds {
ids[i] = fmt.Sprintf("%s%d", *query.SubType, id) ids[i] = *query.SubType + id
} }
sel = append(sel, SelectorElement{Group: ids}) sel = append(sel, SelectorElement{Group: ids})
} }
@ -263,14 +263,14 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
for _, subTypeId := range query.SubTypeIds { for _, subTypeId := range query.SubTypeIds {
sels = append(sels, Selector{ sels = append(sels, Selector{
{String: req.Cluster}, {String: query.Hostname}, {String: req.Cluster}, {String: query.Hostname},
{String: fmt.Sprintf("%s%d", *query.Type, typeId)}, {String: *query.Type + typeId},
{String: fmt.Sprintf("%s%d", *query.SubType, subTypeId)}}) {String: *query.SubType + subTypeId}})
} }
} else { } else {
sels = append(sels, Selector{ sels = append(sels, Selector{
{String: req.Cluster}, {String: req.Cluster},
{String: query.Hostname}, {String: query.Hostname},
{String: fmt.Sprintf("%s%d", *query.Type, typeId)}}) {String: *query.Type + typeId}})
} }
} }
} }

View File

@ -135,7 +135,7 @@ components:
type-ids: type-ids:
type: array type: array
items: items:
type: integer type: string
aggreg: aggreg:
type: boolean type: boolean
description: 'If true, every query result will have exactly one element. Otherwise, the data for every requested type-id/sub-type-id is provided seperately' description: 'If true, every query result will have exactly one element. Otherwise, the data for every requested type-id/sub-type-id is provided seperately'