...
1
2
3
4
5 package analysisflags
6
7 import (
8 "fmt"
9 "net/url"
10
11 "golang.org/x/tools/go/analysis"
12 )
13
14
15
16 func ResolveURL(a *analysis.Analyzer, d analysis.Diagnostic) (string, error) {
17 if d.URL == "" && d.Category == "" && a.URL == "" {
18 return "", nil
19 }
20 raw := d.URL
21 if d.URL == "" && d.Category != "" {
22 raw = "#" + d.Category
23 }
24 u, err := url.Parse(raw)
25 if err != nil {
26 return "", fmt.Errorf("invalid Diagnostic.URL %q: %s", raw, err)
27 }
28 base, err := url.Parse(a.URL)
29 if err != nil {
30 return "", fmt.Errorf("invalid Analyzer.URL %q: %s", a.URL, err)
31 }
32 return base.ResolveReference(u).String(), nil
33 }
34
View as plain text