Skip to content

Commit 2656806

Browse files
committed
edit doc
1 parent 321798b commit 2656806

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

alink.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func Title(httpBody *bytes.Reader) (t string, err error) {
116116
title := ""
117117
node, err := html.Parse(httpBody)
118118
if err != nil {
119-
return title,err
119+
return title, err
120120
}
121121

122122
title, _ = titleText(node)
@@ -130,24 +130,24 @@ func Alink(httpBody *bytes.Reader) (l *[]string, b bool) {
130130
var links []string
131131
node, err := html.Parse(httpBody)
132132
if err != nil {
133-
return &links,false
133+
return &links, false
134134
}
135135
ff, _ := alLink(node, &links)
136136
return ff, true
137137
}
138138

139139
// alLink Get href url
140-
func alLink(node *html.Node, h *[]string) ( f *[]string,n bool) {
140+
func alLink(node *html.Node, h *[]string) (f *[]string, n bool) {
141141
b := false
142142

143143
if isAHrefElement(node) {
144144
for _, a := range node.Attr {
145145
if a.Key == "href" {
146146
s := trimHash(a.Val)
147-
if check(h,s)==false{
147+
if check(h, s) == false {
148148
//*h = make([]string,0,len(*h)+len(s))
149149
//log.Println(cap(f))
150-
*h= append(*h, s)
150+
*h = append(*h, s)
151151
}
152152

153153
return h, true
@@ -177,7 +177,6 @@ func trimHash(l string) string {
177177
return l
178178
}
179179

180-
181180
// Check url exits
182181
func check(sl *[]string, s string) bool {
183182
var check bool
@@ -188,4 +187,4 @@ func check(sl *[]string, s string) bool {
188187
}
189188
}
190189
return check
191-
}
190+
}

alink_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,21 @@ func TestNewRespBody(t *testing.T) {
8585
str := []byte(s)
8686
reader := bytes.NewReader(str)
8787
//str := strings.NewReader(s)
88-
abc ,err := NewRespBody(reader)
89-
if err !=nil{
88+
abc, err := NewRespBody(reader)
89+
if err != nil {
9090
t.Error(err)
9191
}
9292
cc := html.NewTokenizer(abc)
9393

9494
tokenType := cc.Next()
9595

9696
token := cc.Token()
97-
log.Print(tokenType,token)
97+
log.Print(tokenType, token)
9898
if token.DataAtom.String() != "div" {
9999
t.Error("Wrong body ")
100100
}
101101
}
102102

103-
104-
105103
func TestVideo(t *testing.T) {
106104
var reader = `<a href="http://jjjj.com">1</a>
107105
<video src="http://abc.com/ab.mp4">
@@ -126,7 +124,7 @@ func TestVideo(t *testing.T) {
126124
wantS [] string
127125
wantErr bool
128126
}{
129-
{"video", f, []string{"http://abc.com/ab.mp4"}, false },
127+
{"video", f, []string{"http://abc.com/ab.mp4"}, false},
130128
}
131129

132130
//log.Print(tests[0].wantS)
@@ -160,15 +158,14 @@ func TestTitle(t *testing.T) {
160158
p1 := []byte(page1)
161159
a1 := args{bytes.NewReader(p1)}
162160

163-
164161
tests := []struct {
165162
name string
166163
args args
167164
wantT string
168165
wantErr bool
169166
}{
170-
{"title",a,"the title", false},
171-
{"title",a1,"test1", false},
167+
{"title", a, "the title", false},
168+
{"title", a1, "test1", false},
172169
// TODO: Add test cases.
173170
}
174171
for _, tt := range tests {
@@ -189,9 +186,9 @@ func BenchmarkAlink(b *testing.B) {
189186
page := "<html><header><title>the title</title></header><body></body></html>"
190187
p := []byte(page)
191188

192-
for i := 0;i<b.N ;i++{
189+
for i := 0; i < b.N; i++ {
193190
Alink(bytes.NewReader(p))
194191
}
195192
}
196193

197-
//go test -cover -v -coverprofile=c.out
194+
//go test -cover -v -coverprofile=c.out

0 commit comments

Comments
 (0)