fix issue with not found services

This commit is contained in:
pluja 2024-02-25 17:22:55 +01:00
parent 8863f11bcf
commit 9f561e0702

View File

@ -70,20 +70,24 @@ func (p *PbClient) GetServiceByNameOrUrl(id string) (*Service, error) {
return nil, err
}
service := response.Items[0]
if len(response.Items) > 0 {
service := response.Items[0]
// Sort attributes by rating
sort.SliceStable(service.Expand["attributes"], func(i, j int) bool {
ratingOrder := map[string]int{
"bad": 4,
"warn": 3,
"good": 2,
"info": 1,
}
return ratingOrder[service.Expand["attributes"][i].Rating] > ratingOrder[service.Expand["attributes"][j].Rating]
})
// Sort attributes by rating
sort.SliceStable(service.Expand["attributes"], func(i, j int) bool {
ratingOrder := map[string]int{
"bad": 4,
"warn": 3,
"good": 2,
"info": 1,
}
return ratingOrder[service.Expand["attributes"][i].Rating] > ratingOrder[service.Expand["attributes"][j].Rating]
})
return &service, nil
} else {
return nil, fmt.Errorf("Service not found.")
}
return &service, nil
}
func (p *PbClient) GetServiceById(id string) (*Service, error) {