Skip to content

Commit 96de3aa

Browse files
committed
feat(proxymanager): add Rotate method
Signed-off-by: Dwi Siswanto <git@dw1.io>
1 parent 999ea9a commit 96de3aa

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

internal/proxymanager/utils.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"math/rand"
55

66
"github.com/fsnotify/fsnotify"
7+
"github.com/kitabisa/mubeng/pkg/helper"
78
)
89

910
// NextProxy will navigate the next proxy to use
@@ -23,6 +24,26 @@ func (p *ProxyManager) RandomProxy() string {
2324
return p.Proxies[rand.Intn(len(p.Proxies))]
2425
}
2526

27+
// Rotate proxy based on method
28+
//
29+
// Valid methods are "sequent" and "random", default return empty string.
30+
func (p *ProxyManager) Rotate(method string) string {
31+
var proxy string
32+
33+
switch method {
34+
case "sequent":
35+
proxy = p.NextProxy()
36+
case "random":
37+
proxy = p.RandomProxy()
38+
}
39+
40+
if proxy != "" {
41+
proxy = helper.EvalFunc(proxy)
42+
}
43+
44+
return proxy
45+
}
46+
2647
// Watch proxy file from events
2748
func (p *ProxyManager) Watch() (*fsnotify.Watcher, error) {
2849
watcher, err := fsnotify.NewWatcher()

0 commit comments

Comments
 (0)