Skip to content

Commit c59adf4

Browse files
committed
Updated parser to use reader
1 parent b51db8e commit c59adf4

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

html-link-parser/html-link-parser

-371 Bytes
Binary file not shown.

html-link-parser/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import (
44
"flag"
55
"github.com/KyleWardle/gophercises/html-link-parser/parser"
66
"github.com/davecgh/go-spew/spew"
7+
"os"
78
)
89

910
func main() {
1011
example := flag.String("example", "ex1", "")
1112
flag.Parse()
1213

13-
links := parser.ParseLinks("examples/" + *example + ".html")
14+
file, err := os.Open("examples/" + *example + ".html")
15+
if err != nil {
16+
panic(err)
17+
}
18+
defer file.Close()
19+
20+
links := parser.ParseLinks(file)
1421
spew.Dump(links)
1522
}

html-link-parser/parser/parser.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package parser
22

33
import (
44
"golang.org/x/net/html"
5-
"os"
5+
"io"
66
"strings"
77
)
88

@@ -11,14 +11,8 @@ type Link struct {
1111
Text string
1212
}
1313

14-
func ParseLinks(path string) []Link {
15-
file, err := os.Open(path)
16-
if err != nil {
17-
panic(err)
18-
}
19-
defer file.Close()
20-
21-
doc, err := html.Parse(file)
14+
func ParseLinks(reader io.Reader) []Link {
15+
doc, err := html.Parse(reader)
2216
if err != nil {
2317
panic(err)
2418
}

sitemap-builder/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module sitemap-builder
33
go 1.17
44

55
require (
6-
github.com/davecgh/go-spew v1.1.1 // indirect
7-
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
6+
github.com/KyleWardle/gophercises/html-link-parser v0.0.0-20220310104057-b51db8e68298
7+
github.com/davecgh/go-spew v1.1.1
88
)

sitemap-builder/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
github.com/KyleWardle/gophercises/html-link-parser v0.0.0-20220310104057-b51db8e68298 h1:7ZJXsOpgz99YXtC8MiRlVcsQ7VKQQ2x+AkQ7BaVCiFU=
2+
github.com/KyleWardle/gophercises/html-link-parser v0.0.0-20220310104057-b51db8e68298/go.mod h1:KioJO93PUc9DDY1osADSBG6iasXXjasyiqA9VCDoP7o=
13
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
24
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
4-
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
55
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
66
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
77
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

sitemap-builder/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package main
22

33
func main() {
4-
4+
//resp, _ := http.Get("calhoun.io")
5+
//links := parser.ParseLinks( resp.Body)
6+
//spew.Dump(links)
57
}

sitemap-builder/sitemap-builder

1.35 MB
Binary file not shown.

0 commit comments

Comments
 (0)