Skip to content

Commit

Permalink
[fix] change Id to ID to be golint compliant - closes gocolly#81
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed Jan 5, 2018
1 parent cb09030 commit d243a09
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
28 changes: 14 additions & 14 deletions colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type Collector struct {
// the target host's robots.txt file. See http://www.robotstxt.org/ for more
// information.
IgnoreRobotsTxt bool
// Id is the unique identifier of a collector
Id uint32
// ID is the unique identifier of a collector
ID uint32
// DetectCharset can enable character encoding detection for non-utf8 response bodies
// without explicit charset declaration. This feature uses https://github.com/saintfish/chardet
DetectCharset bool
Expand Down Expand Up @@ -204,7 +204,7 @@ func IgnoreRobotsTxt() func(*Collector) {
// ID sets the unique identifier of the Collector.
func ID(id uint32) func(*Collector) {
return func(c *Collector) {
c.Id = id
c.ID = id
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *Collector) Init() {
c.lock = &sync.RWMutex{}
c.robotsMap = make(map[string]*robotstxt.RobotsData)
c.IgnoreRobotsTxt = true
c.Id = atomic.AddUint32(&collectorCounter, 1)
c.ID = atomic.AddUint32(&collectorCounter, 1)
}

// Appengine will replace the Collector's backend http.Client
Expand Down Expand Up @@ -348,7 +348,7 @@ func (c *Collector) scrape(u, method string, depth int, requestData io.Reader, c
Method: method,
Body: requestData,
collector: c,
Id: atomic.AddUint32(&c.requestCount, 1),
ID: atomic.AddUint32(&c.requestCount, 1),
}

c.handleOnRequest(request)
Expand Down Expand Up @@ -610,18 +610,18 @@ func (c *Collector) SetProxyFunc(p ProxyFunc) {
}
}

func createEvent(eventType string, requestId, collectorId uint32, kvargs map[string]string) *debug.Event {
func createEvent(eventType string, requestID, collectorID uint32, kvargs map[string]string) *debug.Event {
return &debug.Event{
CollectorId: collectorId,
RequestId: requestId,
CollectorID: collectorID,
RequestID: requestID,
Type: eventType,
Values: kvargs,
}
}

func (c *Collector) handleOnRequest(r *Request) {
if c.debugger != nil {
c.debugger.Event(createEvent("request", r.Id, c.Id, map[string]string{
c.debugger.Event(createEvent("request", r.ID, c.ID, map[string]string{
"url": r.URL.String(),
}))
}
Expand All @@ -632,7 +632,7 @@ func (c *Collector) handleOnRequest(r *Request) {

func (c *Collector) handleOnResponse(r *Response) {
if c.debugger != nil {
c.debugger.Event(createEvent("response", r.Request.Id, c.Id, map[string]string{
c.debugger.Event(createEvent("response", r.Request.ID, c.ID, map[string]string{
"url": r.Request.URL.String(),
"status": http.StatusText(r.StatusCode),
}))
Expand All @@ -655,7 +655,7 @@ func (c *Collector) handleOnHTML(resp *Response) {
for _, n := range s.Nodes {
e := NewHTMLElementFromSelectionNode(resp, s, n)
if c.debugger != nil {
c.debugger.Event(createEvent("html", resp.Request.Id, c.Id, map[string]string{
c.debugger.Event(createEvent("html", resp.Request.ID, c.ID, map[string]string{
"selector": cc.Selector,
"url": resp.Request.URL.String(),
}))
Expand All @@ -680,7 +680,7 @@ func (c *Collector) handleOnError(response *Response, err error, request *Reques
}
}
if c.debugger != nil {
c.debugger.Event(createEvent("error", request.Id, c.Id, map[string]string{
c.debugger.Event(createEvent("error", request.ID, c.ID, map[string]string{
"url": request.URL.String(),
"status": http.StatusText(response.StatusCode),
}))
Expand All @@ -696,7 +696,7 @@ func (c *Collector) handleOnError(response *Response, err error, request *Reques

func (c *Collector) handleOnScraped(r *Response) {
if c.debugger != nil {
c.debugger.Event(createEvent("scraped", r.Request.Id, c.Id, map[string]string{
c.debugger.Event(createEvent("scraped", r.Request.ID, c.ID, map[string]string{
"url": r.Request.URL.String(),
}))
}
Expand Down Expand Up @@ -748,7 +748,7 @@ func (c *Collector) Clone() *Collector {
AllowedDomains: c.AllowedDomains,
CacheDir: c.CacheDir,
DisallowedDomains: c.DisallowedDomains,
Id: atomic.AddUint32(&collectorCounter, 1),
ID: atomic.AddUint32(&collectorCounter, 1),
IgnoreRobotsTxt: c.IgnoreRobotsTxt,
MaxBodySize: c.MaxBodySize,
MaxDepth: c.MaxDepth,
Expand Down
4 changes: 2 additions & 2 deletions colly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func TestNewCollector(t *testing.T) {
} {
c := NewCollector(ID(id))

if got, want := c.Id, id; got != want {
t.Fatalf("c.Id = %d, want %d", got, want)
if got, want := c.ID, id; got != want {
t.Fatalf("c.ID = %d, want %d", got, want)
}
}
})
Expand Down
8 changes: 4 additions & 4 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package debug
type Event struct {
// Type is the type of the event
Type string
// RequestId identifies the HTTP request of the Event
RequestId uint32
// CollectorId identifies the collector of the Event
CollectorId uint32
// RequestID identifies the HTTP request of the Event
RequestID uint32
// CollectorID identifies the collector of the Event
CollectorID uint32
// Values contains the event's key-value pairs. Different type of events
// can return different key-value pairs
Values map[string]string
Expand Down
2 changes: 1 addition & 1 deletion debug/logdebugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (l *LogDebugger) Init() error {
// Event receives Collector events and prints them to STDERR
func (l *LogDebugger) Event(e *Event) {
i := atomic.AddInt32(&l.counter, 1)
l.logger.Printf("[%06d] %d [%6d - %s] %q (%s)\n", i, e.CollectorId, e.RequestId, e.Type, e.Values, time.Since(l.start))
l.logger.Printf("[%06d] %d [%6d - %s] %q (%s)\n", i, e.CollectorID, e.RequestID, e.Type, e.Values, time.Since(l.start))
}
18 changes: 9 additions & 9 deletions debug/webdebugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type WebDebugger struct {
}

type requestInfo struct {
Url string
URL string
Started time.Time
Duration time.Duration
ResponseStatus string
Id uint32
CollectorId uint32
ID uint32
CollectorID uint32
}

// Init initializes the WebDebugger
Expand All @@ -49,18 +49,18 @@ func (w *WebDebugger) Init() error {
func (w *WebDebugger) Event(e *Event) {
switch e.Type {
case "request":
w.CurrentRequests[e.RequestId] = requestInfo{
Url: e.Values["url"],
w.CurrentRequests[e.RequestID] = requestInfo{
URL: e.Values["url"],
Started: time.Now(),
Id: e.RequestId,
CollectorId: e.CollectorId,
ID: e.RequestID,
CollectorID: e.CollectorID,
}
case "response", "error":
r := w.CurrentRequests[e.RequestId]
r := w.CurrentRequests[e.RequestID]
r.Duration = time.Since(r.Started)
r.ResponseStatus = e.Values["status"]
w.RequestLog = append(w.RequestLog, r)
delete(w.CurrentRequests, e.RequestId)
delete(w.CurrentRequests, e.RequestID)
}
}

Expand Down
4 changes: 2 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Request struct {
Method string
// Body is the request body which is used on POST/PUT requests
Body io.Reader
// Unique identifier of the request
Id uint32
// ID is the Unique identifier of the request
ID uint32
collector *Collector
}

Expand Down

0 comments on commit d243a09

Please sign in to comment.