@@ -131,8 +131,8 @@ type Collector struct {
131131 requestHeadersCallbacks []RequestCallback
132132 errorCallbacks []ErrorCallback
133133 scrapedCallbacks []ScrapedCallback
134- requestCount uint32
135- responseCount uint32
134+ requestCount atomic. Uint32
135+ responseCount atomic. Uint32
136136 backend * httpBackend
137137 wg * sync.WaitGroup
138138 lock * sync.RWMutex
@@ -623,7 +623,7 @@ func (c *Collector) UnmarshalRequest(r []byte) (*Request, error) {
623623 Depth : req .Depth ,
624624 Body : bytes .NewReader (req .Body ),
625625 Ctx : ctx ,
626- ID : atomic . AddUint32 ( & c .requestCount , 1 ),
626+ ID : c .requestCount . Add ( 1 ),
627627 Headers : & req .Headers ,
628628 collector : c ,
629629 }, nil
@@ -698,7 +698,7 @@ func (c *Collector) fetch(u, method string, depth int, requestData io.Reader, ct
698698 Method : method ,
699699 Body : requestData ,
700700 collector : c ,
701- ID : atomic . AddUint32 ( & c .requestCount , 1 ),
701+ ID : c .requestCount . Add ( 1 ),
702702 }
703703
704704 if req .Header .Get ("Accept" ) == "" {
@@ -740,7 +740,7 @@ func (c *Collector) fetch(u, method string, depth int, requestData io.Reader, ct
740740 if err := c .handleOnError (response , err , request , ctx ); err != nil {
741741 return err
742742 }
743- atomic . AddUint32 ( & c .responseCount , 1 )
743+ c .responseCount . Add ( 1 )
744744 response .Ctx = ctx
745745 response .Request = request
746746 response .Trace = hTrace
@@ -772,7 +772,7 @@ func (c *Collector) requestCheck(parsedURL *url.URL, method string, getBody func
772772 if c .MaxDepth > 0 && c .MaxDepth < depth {
773773 return ErrMaxDepth
774774 }
775- if c .MaxRequests > 0 && c .requestCount >= c .MaxRequests {
775+ if c .MaxRequests > 0 && c .requestCount . Load () >= c .MaxRequests {
776776 return ErrMaxRequests
777777 }
778778 if err := c .checkFilters (u , parsedURL .Hostname ()); err != nil {
@@ -906,8 +906,8 @@ func (c *Collector) checkRobots(u *url.URL) error {
906906func (c * Collector ) String () string {
907907 return fmt .Sprintf (
908908 "Requests made: %d (%d responses) | Callbacks: OnRequest: %d, OnHTML: %d, OnResponse: %d, OnError: %d" ,
909- atomic . LoadUint32 ( & c .requestCount ),
910- atomic . LoadUint32 ( & c .responseCount ),
909+ c .requestCount . Load ( ),
910+ c .responseCount . Load ( ),
911911 len (c .requestCallbacks ),
912912 len (c .htmlCallbacks ),
913913 len (c .responseCallbacks ),
0 commit comments