fix(style): check of WriteString error return

This commit is contained in:
Łukasz Mierzwa
2018-08-11 22:54:45 +01:00
parent b2a0f61d4e
commit def3236645
2 changed files with 30 additions and 5 deletions

View File

@@ -6,6 +6,8 @@ import (
"io"
"github.com/cnf/structhash"
log "github.com/sirupsen/logrus"
)
// AlertList is flat list of UnseeAlert objects
@@ -46,8 +48,17 @@ type AlertGroup struct {
// it should be unique for each AlertGroup
func (ag AlertGroup) LabelsFingerprint() string {
agIDHasher := sha1.New()
io.WriteString(agIDHasher, ag.Receiver)
io.WriteString(agIDHasher, fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1)))
_, err := io.WriteString(agIDHasher, ag.Receiver)
if err != nil {
log.Errorf("Failed to write receiver value to alertgroup '%s' fingerprint: %s", ag.ID, err)
}
_, err = io.WriteString(agIDHasher, fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1)))
if err != nil {
log.Errorf("Failed to write labels sha1 value to alertgroup '%s' fingerprint: %s", ag.ID, err)
}
return fmt.Sprintf("%x", agIDHasher.Sum(nil))
}
@@ -55,7 +66,10 @@ func (ag AlertGroup) LabelsFingerprint() string {
func (ag AlertGroup) ContentFingerprint() string {
h := sha1.New()
for _, alert := range ag.Alerts {
io.WriteString(h, alert.ContentFingerprint())
_, err := io.WriteString(h, alert.ContentFingerprint())
if err != nil {
log.Errorf("Failed to write alert fingerprint value to alertgroup '%s' fingerprint: %s", ag.ID, err)
}
}
return fmt.Sprintf("%x", h.Sum(nil))
}

View File

@@ -10,12 +10,23 @@ import (
"github.com/prymitive/unsee/internal/slices"
"github.com/hansrodtang/randomcolor"
log "github.com/sirupsen/logrus"
)
func labelToSeed(key string, val string) int64 {
h := sha1.New()
io.WriteString(h, key)
io.WriteString(h, val)
_, err := io.WriteString(h, key)
if err != nil {
log.Errorf("Failed to write label key '%s' to the seed sha1: %s", key, err)
}
_, err = io.WriteString(h, val)
if err != nil {
log.Errorf("Failed to write label value '%s' to the seed sha1: %s", val, err)
}
var seed int64
for _, i := range h.Sum(nil) {
seed += int64(i)