Files
karma/internal/slices/slices.go
Łukasz Mierzwa 8b5862d44b chore(api): store cluster as a dict
This will allow silences to be grouped by cluster rather than by alertmanager instance
2018-11-30 23:59:58 +00:00

43 lines
871 B
Go

package slices
import (
"crypto/sha1"
"fmt"
)
// BoolInSlice returns true if given bool is found in a slice of bools
func BoolInSlice(boolArray []bool, value bool) bool {
for _, s := range boolArray {
if s == value {
return true
}
}
return false
}
// StringInSlice returns true if given string is found in a slice of strings
func StringInSlice(stringArray []string, value string) bool {
for _, s := range stringArray {
if s == value {
return true
}
}
return false
}
// StringSliceToSHA1 returns a SHA1 hash computed from a slice of strings
func StringSliceToSHA1(stringArray []string) (string, error) {
h := sha1.New()
for _, s := range stringArray {
_, err := h.Write([]byte(s))
if err != nil {
return "", err
}
_, err = h.Write([]byte("\n"))
if err != nil {
return "", err
}
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}