Files
karma/internal/transform/links.go
Łukasz Mierzwa 5d4ae47888 Convert all packages to be internal
Internal packages are supported by Go 1.5+, any package in /internal/ dir is only importable from the same repo. This will cleanup main dir a bit and provide better namespace for unsee subpackages
2017-08-04 16:21:27 -07:00

36 lines
765 B
Go

package transform
import (
"net/url"
"github.com/cloudflare/unsee/internal/slices"
)
// 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 slices.StringInSlice(schemes, u.Scheme) {
links[k] = v
} else {
annotations[k] = v
}
}
return annotations, links
}