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"`
ScaleFactor Float `json:"scale-by,omitempty"`
Type *string `json:"type,omitempty"`
TypeIds []int `json:"type-ids,omitempty"`
TypeIds []string `json:"type-ids,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) {
@ -235,22 +235,22 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
sel := Selector{{String: req.Cluster}, {String: query.Hostname}}
if query.Type != nil {
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 {
ids := make([]string, len(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})
}
if query.SubType != nil {
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 {
ids := make([]string, len(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})
}
@ -263,14 +263,14 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
for _, subTypeId := range query.SubTypeIds {
sels = append(sels, Selector{
{String: req.Cluster}, {String: query.Hostname},
{String: fmt.Sprintf("%s%d", *query.Type, typeId)},
{String: fmt.Sprintf("%s%d", *query.SubType, subTypeId)}})
{String: *query.Type + typeId},
{String: *query.SubType + subTypeId}})
}
} else {
sels = append(sels, Selector{
{String: req.Cluster},
{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: array
items:
type: integer
type: string
aggreg:
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'