Skip to content
This repository was archived by the owner on Feb 13, 2021. It is now read-only.

Commit b121f62

Browse files
committed
fix staticcheck issues
1 parent 7dd5539 commit b121f62

File tree

8 files changed

+64
-65
lines changed

8 files changed

+64
-65
lines changed

cmd/gryffin-distributed/main.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ import (
2525
"github.com/yahoo/gryffin/renderer"
2626
)
2727

28-
var storage = flag.String("storage", "memory", "storag method or the storage url")
29-
var service string
30-
var url string
31-
var wg sync.WaitGroup
32-
var wq chan bool
33-
34-
var t *gryffin.Scan
35-
36-
var logWriter io.Writer
37-
var store *gryffin.GryffinStore
28+
var (
29+
// storage is currently unused - TODO: use or remove
30+
// storage = flag.String("storage", "memory", "storag method or the storage url")
31+
service string
32+
url string
33+
wg sync.WaitGroup
34+
wq chan bool
35+
36+
t *gryffin.Scan
37+
38+
logWriter io.Writer
39+
store *gryffin.GryffinStore
40+
)
3841

3942
// var method = flag.String("method", "GET", "the HTTP method for the request.")
4043
// var url string
@@ -47,11 +50,6 @@ func usage() {
4750
flag.PrintDefaults()
4851
}
4952

50-
// handler
51-
type h struct {
52-
HandleMessage nsq.HandlerFunc
53-
}
54-
5553
func captureCtrlC() {
5654
sigChan := make(chan os.Signal, 1)
5755
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

cmd/gryffin-standalone/main.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,18 @@ func linkChannels(s *gryffin.Scan) {
124124
// Start, Poke -> RateLimit
125125
go func() {
126126
for scan := range chanStart {
127-
err := scan.Poke(&http.Client{})
128-
if err != nil {
129-
// if scan.HitCount <= 5 {
130-
// go func() {
131-
// time.Sleep(5 * time.Second)
132-
// chanStart <- scan
133-
// }()
134-
// }
135-
// continue
136-
}
127+
// TODO: add error handling
128+
// err := scan.Poke(&http.Client{})
129+
_ = scan.Poke(&http.Client{})
130+
// if err != nil {
131+
// if scan.HitCount <= 5 {
132+
// go func() {
133+
// time.Sleep(5 * time.Second)
134+
// chanStart <- scan
135+
// }()
136+
// }
137+
// continue
138+
// }
137139
chanRateLimit <- scan
138140
}
139141
}()

data/memory.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,58 +73,58 @@ func NewMemoryStore() *MemoryStore {
7373
func convertIntToPtr(v interface{}) (s *int64, ok bool) {
7474
var t int64
7575

76-
switch v.(type) {
76+
switch v := v.(type) {
7777

7878
case int:
79-
t = int64(v.(int))
79+
t = int64(v)
8080
case int8:
81-
t = int64(v.(int8))
81+
t = int64(v)
8282
case int16:
83-
t = int64(v.(int16))
83+
t = int64(v)
8484
case int32:
85-
t = int64(v.(int32))
85+
t = int64(v)
8686
case int64:
87-
t = int64(v.(int64))
87+
t = v
8888
case uint:
89-
t = int64(v.(uint))
89+
t = int64(v)
9090
case uint8:
91-
t = int64(v.(uint8))
91+
t = int64(v)
9292
case uint16:
93-
t = int64(v.(uint16))
93+
t = int64(v)
9494
case uint32:
95-
t = int64(v.(uint32))
95+
t = int64(v)
9696
case uint64:
97-
t = int64(v.(uint64))
97+
t = int64(v)
9898
}
9999

100100
return &t, ok
101101
}
102102

103103
func convertPtrToInt(v interface{}) (s int64, ok bool) {
104104

105-
switch v.(type) {
105+
switch v := v.(type) {
106106

107107
case *int:
108-
return int64(*(v.(*int))), true
108+
return int64(*v), true
109109
case *int8:
110-
return int64(*(v.(*int8))), true
110+
return int64(*v), true
111111
case *int16:
112-
return int64(*(v.(*int16))), true
112+
return int64(*v), true
113113
case *int32:
114-
return int64(*(v.(*int32))), true
114+
return int64(*v), true
115115
case *int64:
116-
return int64(*(v.(*int64))), true
116+
return *v, true
117117

118118
case *uint:
119-
return int64(*(v.(*uint))), true
119+
return int64(*v), true
120120
case *uint8:
121-
return int64(*(v.(*uint8))), true
121+
return int64(*v), true
122122
case *uint16:
123-
return int64(*(v.(*uint16))), true
123+
return int64(*v), true
124124
case *uint32:
125-
return int64(*(v.(*uint32))), true
125+
return int64(*v), true
126126
case *uint64:
127-
return int64(*(v.(*uint64))), true
127+
return int64(*v), true
128128
}
129129

130130
return

gryffin.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ func (s *Scan) MergeRequest(req *http.Request) {
148148
}
149149

150150
// TODO - drop if Method, URL, Body are same..
151-
if req == s.Request {
152-
// s.Logf("Result after merge generate same request.", nil)
153-
}
151+
// if req == s.Request {
152+
// s.Logf("Result after merge generate same request.", nil)
153+
// }
154154

155155
// swap
156156
prevReq := s.Request
@@ -213,9 +213,9 @@ func (s *Scan) Poke(client HTTPDoer) (err error) {
213213
s.Logm("Poke", "Poking")
214214

215215
// Add 5s timeout if it is http.Client
216-
switch client.(type) {
216+
switch client := client.(type) {
217217
case *http.Client:
218-
client.(*http.Client).Timeout = time.Duration(3) * time.Second
218+
client.Timeout = time.Duration(3) * time.Second
219219
}
220220

221221
// delete the similarity case for the domain.
@@ -264,9 +264,9 @@ func (s *Scan) UpdateFingerprint() {
264264
if f.Request == 0 {
265265
f.Request = hash(s.Request.URL.String() + "\n" + s.RequestBody)
266266
}
267-
if f.RequestFull == 0 {
268-
// TODO
269-
}
267+
// if f.RequestFull == 0 {
268+
// TODO
269+
// }
270270
}
271271

272272
if f.ResponseSimilarity == 0 {

gryffin_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func TestNewScan(t *testing.T) {
3535
t.Error("Scan is nil.")
3636
}
3737
// TODO - verify s.DomainAllowed.
38-
t.Logf("Jobid: %s.", s.Job.ID)
3938
}
4039

4140
func TestNewScanInvalid(t *testing.T) {

renderer/base_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ func testCrawlAsync(t *testing.T, r gryffin.Renderer) {
2020

2121
s := gryffin.NewScan("GET", url, "")
2222
r.Do(s)
23-
s = <-r.GetRequestBody()
24-
// t.Logf("Got async body %s", s)
23+
<-r.GetRequestBody()
2524
for link := range r.GetLinks() {
2625
t.Logf("Got link %s", link.Request.URL)
2726
}

renderer/noscript.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"strings"
1212
"time"
13+
1314
// "sync"
1415

1516
"github.com/yahoo/gryffin"
@@ -75,9 +76,10 @@ func (r *NoScriptRenderer) Do(s *gryffin.Scan) {
7576
if link.IsScanAllowed() {
7677
r.chanLinks <- link
7778
}
78-
} else {
79-
// ignore relative URL. TOFIX.
8079
}
80+
// else {
81+
// FIXME: ignore relative URL.
82+
// }
8183
} else {
8284
log.Printf("error in building request: %s", err)
8385
}

session.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ import (
1010
"strconv"
1111
"time"
1212

13-
"github.com/yahoo/gryffin/data"
14-
"github.com/yahoo/gryffin/html-distance"
13+
distance "github.com/yahoo/gryffin/html-distance"
1514
)
1615

1716
type GryffinStore struct {
1817
Oracles map[string]*distance.Oracle
1918
Hashes map[string]bool
2019
Hits map[string]int
21-
store data.Store
22-
snd chan []byte
23-
rcv chan []byte
20+
// store data.Store - currently unused, TODO: use or remove
21+
snd chan []byte
22+
rcv chan []byte
2423
}
2524

2625
type PublishMessage struct {

0 commit comments

Comments
 (0)