mirror of
https://github.com/prymitive/karma
synced 2026-05-13 03:56:59 +00:00
Use url.Parse instead of govalidator for detecting links
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user