-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.go
More file actions
56 lines (52 loc) · 1.21 KB
/
parse.go
File metadata and controls
56 lines (52 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"io"
"strconv"
"github.com/PuerkitoBio/goquery"
)
type ResultLine struct {
resultType string
description string
fl int
fc int
ll int
lc int
}
func parse(r io.Reader) ([]ResultLine, error) {
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
return nil, err
}
results := []ResultLine{}
for _, label := range []string{".error", ".warning", ".info"} {
doc.Find(label).Each(func(_ int, s *goquery.Selection) {
description := s.Find("p span").First().Text()
resultType := s.Find("p strong").Text()
fl, err := strconv.Atoi(s.Find("p.location span.first-line").Text())
if err != nil {
return
}
fc, err := strconv.Atoi(s.Find("p.location span.first-col").Text())
if err != nil {
return
}
ll, err := strconv.Atoi(s.Find("p.location span.last-line").Text())
if err != nil {
return
}
lc, err := strconv.Atoi(s.Find("p.location span.last-col").Text())
if err != nil {
return
}
results = append(results, ResultLine{
resultType: resultType,
description: description,
fl: fl,
fc: fc,
ll: ll,
lc: lc,
})
})
}
return results, nil
}