Use url.Parse instead of govalidator for detecting links

This commit is contained in:
Łukasz Mierzwa
2017-04-14 23:31:07 -07:00
parent b2aae22086
commit 34ab5094f4

View File

@@ -1,6 +1,13 @@
package transform
import "github.com/asaskevich/govalidator"
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
@@ -10,7 +17,10 @@ func DetectLinks(sourceAnnotations map[string]string) (map[string]string, map[st
annotations := make(map[string]string)
for k, v := range sourceAnnotations {
if govalidator.IsURL(v) {
u, err := url.Parse(v)
if err != nil {
annotations[k] = v
} else if stringInSlice(schemes, u.Scheme) {
links[k] = v
} else {
annotations[k] = v