-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathmain.go
83 lines (70 loc) · 1.57 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
// there is a lot of better library out there. specially I hate the standard flag library.
// but I want this one, clean and tidy. so hell with it :)
import (
"bufio"
"flag"
"io"
"log"
"os"
"path/filepath"
)
var (
listFile *string
foxy *string
pac *string
ppx *string
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func openFile(f string) (io.WriteCloser, error) {
fl, err := os.Create(f)
if err != nil {
return nil, err
}
return fl, nil
}
func load(path string) ([]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var domains []string
sc := bufio.NewScanner(f)
for sc.Scan() {
domains = append(domains, sc.Text())
}
return domains, sc.Err()
}
func execute(p string, fn func(io.Writer, ...string) error, domains ...string) error {
if p != "" {
fl, err := openFile(p)
check(err)
defer fl.Close()
return fn(fl, domains...)
}
return nil
}
func main() {
flag.Parse()
domains, err := load(*listFile)
check(err)
check(execute(*foxy, foxyProxy, domains...))
check(execute(*ppx, proxifier, domains...))
check(execute(*pac, pacFile, domains...))
}
func init() {
p, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
p = filepath.Join(p, "domains")
listFile = flag.String("domains", p, "domains file list")
foxy = flag.String("foxyproxy", "", "path to build foxyproxy pattern, empty means ignore")
pac = flag.String("pac", "", "path to build pac file, empty means ignore")
ppx = flag.String("proxifier", "", "path to build proxifier config, empty means ignore")
}