Content-Length: 259980 | pFad | http://github.com/mubeng/mubeng/commit/8a90f36125c6089f2f61a36a71ed18b8c82fbae0

DC feat(proxymanager): add `Count` method · mubeng/mubeng@8a90f36 · GitHub
Skip to content

Commit

Permalink
feat(proxymanager): add Count method
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <git@dw1.io>
  • Loading branch information
dwisiswant0 committed Sep 15, 2024
1 parent e51a07a commit 8a90f36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/proxymanager/proxymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func New(filename string) (*ProxyManager, error) {
}
}

manager.Length = len(manager.Proxies)
manager.Count()

if manager.Length < 1 {
return manager, fmt.Errorf("open %s: has no valid proxy URLs", filename)
}
Expand Down
11 changes: 9 additions & 2 deletions internal/proxymanager/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ import (
"github.com/kitabisa/mubeng/pkg/helper"
)

// Count counts total proxies
func (p *ProxyManager) Count() int {
p.Length = len(p.Proxies)

return p.Length
}

// NextProxy will navigate the next proxy to use
func (p *ProxyManager) NextProxy() string {
p.CurrentIndex++
if p.CurrentIndex > len(p.Proxies)-1 {
if p.CurrentIndex > p.Count()-1 {
p.CurrentIndex = 0
}

Expand All @@ -22,7 +29,7 @@ func (p *ProxyManager) NextProxy() string {

// RandomProxy will choose a proxy randomly from the list
func (p *ProxyManager) RandomProxy() string {
return p.Proxies[rand.Intn(len(p.Proxies))]
return p.Proxies[rand.Intn(p.Count())]
}

// RemoveProxy removes target proxy from proxy pool
Expand Down

0 comments on commit 8a90f36

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/mubeng/mubeng/commit/8a90f36125c6089f2f61a36a71ed18b8c82fbae0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy