Skip to content

Commit

Permalink
fix staticcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitris committed Apr 29, 2020
1 parent 7dd5539 commit b121f62
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 65 deletions.
28 changes: 13 additions & 15 deletions cmd/gryffin-distributed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ import (
"github.com/yahoo/gryffin/renderer"
)

var storage = flag.String("storage", "memory", "storag method or the storage url")
var service string
var url string
var wg sync.WaitGroup
var wq chan bool

var t *gryffin.Scan

var logWriter io.Writer
var store *gryffin.GryffinStore
var (
// storage is currently unused - TODO: use or remove
// storage = flag.String("storage", "memory", "storag method or the storage url")
service string
url string
wg sync.WaitGroup
wq chan bool

t *gryffin.Scan

logWriter io.Writer
store *gryffin.GryffinStore
)

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

// handler
type h struct {
HandleMessage nsq.HandlerFunc
}

func captureCtrlC() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
Expand Down
22 changes: 12 additions & 10 deletions cmd/gryffin-standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,18 @@ func linkChannels(s *gryffin.Scan) {
// Start, Poke -> RateLimit
go func() {
for scan := range chanStart {
err := scan.Poke(&http.Client{})
if err != nil {
// if scan.HitCount <= 5 {
// go func() {
// time.Sleep(5 * time.Second)
// chanStart <- scan
// }()
// }
// continue
}
// TODO: add error handling
// err := scan.Poke(&http.Client{})
_ = scan.Poke(&http.Client{})
// if err != nil {
// if scan.HitCount <= 5 {
// go func() {
// time.Sleep(5 * time.Second)
// chanStart <- scan
// }()
// }
// continue
// }
chanRateLimit <- scan
}
}()
Expand Down
44 changes: 22 additions & 22 deletions data/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,58 @@ func NewMemoryStore() *MemoryStore {
func convertIntToPtr(v interface{}) (s *int64, ok bool) {
var t int64

switch v.(type) {
switch v := v.(type) {

case int:
t = int64(v.(int))
t = int64(v)
case int8:
t = int64(v.(int8))
t = int64(v)
case int16:
t = int64(v.(int16))
t = int64(v)
case int32:
t = int64(v.(int32))
t = int64(v)
case int64:
t = int64(v.(int64))
t = v
case uint:
t = int64(v.(uint))
t = int64(v)
case uint8:
t = int64(v.(uint8))
t = int64(v)
case uint16:
t = int64(v.(uint16))
t = int64(v)
case uint32:
t = int64(v.(uint32))
t = int64(v)
case uint64:
t = int64(v.(uint64))
t = int64(v)
}

return &t, ok
}

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

switch v.(type) {
switch v := v.(type) {

case *int:
return int64(*(v.(*int))), true
return int64(*v), true
case *int8:
return int64(*(v.(*int8))), true
return int64(*v), true
case *int16:
return int64(*(v.(*int16))), true
return int64(*v), true
case *int32:
return int64(*(v.(*int32))), true
return int64(*v), true
case *int64:
return int64(*(v.(*int64))), true
return *v, true

case *uint:
return int64(*(v.(*uint))), true
return int64(*v), true
case *uint8:
return int64(*(v.(*uint8))), true
return int64(*v), true
case *uint16:
return int64(*(v.(*uint16))), true
return int64(*v), true
case *uint32:
return int64(*(v.(*uint32))), true
return int64(*v), true
case *uint64:
return int64(*(v.(*uint64))), true
return int64(*v), true
}

return
Expand Down
16 changes: 8 additions & 8 deletions gryffin.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ func (s *Scan) MergeRequest(req *http.Request) {
}

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

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

// Add 5s timeout if it is http.Client
switch client.(type) {
switch client := client.(type) {
case *http.Client:
client.(*http.Client).Timeout = time.Duration(3) * time.Second
client.Timeout = time.Duration(3) * time.Second
}

// delete the similarity case for the domain.
Expand Down Expand Up @@ -264,9 +264,9 @@ func (s *Scan) UpdateFingerprint() {
if f.Request == 0 {
f.Request = hash(s.Request.URL.String() + "\n" + s.RequestBody)
}
if f.RequestFull == 0 {
// TODO
}
// if f.RequestFull == 0 {
// TODO
// }
}

if f.ResponseSimilarity == 0 {
Expand Down
1 change: 0 additions & 1 deletion gryffin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func TestNewScan(t *testing.T) {
t.Error("Scan is nil.")
}
// TODO - verify s.DomainAllowed.
t.Logf("Jobid: %s.", s.Job.ID)
}

func TestNewScanInvalid(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions renderer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func testCrawlAsync(t *testing.T, r gryffin.Renderer) {

s := gryffin.NewScan("GET", url, "")
r.Do(s)
s = <-r.GetRequestBody()
// t.Logf("Got async body %s", s)
<-r.GetRequestBody()
for link := range r.GetLinks() {
t.Logf("Got link %s", link.Request.URL)
}
Expand Down
6 changes: 4 additions & 2 deletions renderer/noscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"strings"
"time"

// "sync"

"github.com/yahoo/gryffin"
Expand Down Expand Up @@ -75,9 +76,10 @@ func (r *NoScriptRenderer) Do(s *gryffin.Scan) {
if link.IsScanAllowed() {
r.chanLinks <- link
}
} else {
// ignore relative URL. TOFIX.
}
// else {
// FIXME: ignore relative URL.
// }
} else {
log.Printf("error in building request: %s", err)
}
Expand Down
9 changes: 4 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import (
"strconv"
"time"

"github.com/yahoo/gryffin/data"
"github.com/yahoo/gryffin/html-distance"
distance "github.com/yahoo/gryffin/html-distance"
)

type GryffinStore struct {
Oracles map[string]*distance.Oracle
Hashes map[string]bool
Hits map[string]int
store data.Store
snd chan []byte
rcv chan []byte
// store data.Store - currently unused, TODO: use or remove
snd chan []byte
rcv chan []byte
}

type PublishMessage struct {
Expand Down

0 comments on commit b121f62

Please sign in to comment.