Don't iterate a dict, just grab the key

This is slow, it's a dict, not need to iterate that.
This commit is contained in:
Łukasz Mierzwa
2017-07-08 14:20:08 -07:00
parent 51c2ed7f10
commit fb75e6b083

View File

@@ -254,13 +254,11 @@ func (am *Alertmanager) SilenceByID(id string) (models.Silence, error) {
am.lock.RLock()
defer am.lock.RUnlock()
for k, v := range am.silences {
if k == id {
return models.Silence(v), nil
}
s, found := am.silences[id]
if !found {
return models.Silence{}, fmt.Errorf("Silence '%s' not found", id)
}
return models.Silence{}, fmt.Errorf("Silence '%s' not found", id)
return s, nil
}
// Colors returns a copy of all color maps