File tree Expand file tree Collapse file tree 7 files changed +18
-15
lines changed Expand file tree Collapse file tree 7 files changed +18
-15
lines changed Original file line number Diff line number Diff 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
910func 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}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package parser
22
33import (
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 }
Original file line number Diff line number Diff line change @@ -3,6 +3,6 @@ module sitemap-builder
33go 1.17
44
55require (
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)
Original file line number Diff line number Diff line change 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 =
13github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
24github.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 =
55golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc =
66golang.org/x/net v0.0.0-20220225172249-27dd8689420f /go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk =
77golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
Original file line number Diff line number Diff line change 11package main
22
33func main () {
4-
4+ //resp, _ := http.Get("calhoun.io")
5+ //links := parser.ParseLinks( resp.Body)
6+ //spew.Dump(links)
57}
You can’t perform that action at this time.
0 commit comments