mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
32 lines
705 B
Go
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
|
|
}
|