From 34ab5094f416c7867d4df4c2da6222b759dbb673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 14 Apr 2017 23:31:07 -0700 Subject: [PATCH] Use url.Parse instead of govalidator for detecting links --- transform/links.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/transform/links.go b/transform/links.go index 23495836c..99d1c482c 100644 --- a/transform/links.go +++ b/transform/links.go @@ -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