-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseragent.go
53 lines (46 loc) · 988 Bytes
/
useragent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"bufio"
"container/ring"
"fmt"
"os"
"sync"
)
type UserAgentManager struct {
pp *ring.Ring
}
var singleton *UserAgentManager
var once sync.Once
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}
func GetUAManager() *UserAgentManager {
once.Do(func() {
coffee, _ := readLines(UA_FILE)
fmt.Printf("[-] Loaded %d User-Agents\n\n", len(coffee))
var s UserAgentManager
s.pp = ring.New(len(coffee))
// populate the ring buffer
for i := 0; i < s.pp.Len(); i++ {
s.pp.Value = coffee[i]
s.pp = s.pp.Next()
}
singleton = &s
//singleton = &UserAgentManager{*ring.New(len(coffee))}
})
return singleton
}
func (m *UserAgentManager) GetUserAgent() string {
m.pp = m.pp.Next()
return m.pp.Value.(string)
}