Files
karma/transform/links.go
2017-04-16 08:27:41 -07:00

32 lines
705 B
Go

package transform
import "net/url"
// list of URI schema which we turn into links in the UI
var schemes = []string{
"ftp",
"http",
"https",
}
// DetectLinks takes alert annotation dict and returns two dicts:
// first with regular annotations
// secondd with annotations where values are URLs
func DetectLinks(sourceAnnotations map[string]string) (map[string]string, map[string]string) {
links := make(map[string]string)
annotations := make(map[string]string)
for k, v := range sourceAnnotations {
u, err := url.Parse(v)
if err != nil {
annotations[k] = v
} else if stringInSlice(schemes, u.Scheme) {
links[k] = v
} else {
annotations[k] = v
}
}
return annotations, links
}