forked from txthinking/blackwhite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (81 loc) · 2.12 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
84
85
86
87
88
89
//
// https://github.com/txthinking/pac
//
package main
import (
"log"
"net/http"
"os"
"github.com/codegangsta/cli"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
)
var listen string
var whiteList string
var whiteCIDR string
var blackList string
var customizeMap string
var cycle int
func main() {
app := cli.NewApp()
app.Name = "PAC"
app.Version = "20170516"
app.Usage = "A smart PAC file"
app.Author = "Cloud"
app.Email = "[email protected]"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "listen",
Value: ":1901",
Usage: "Listen address.",
Destination: &listen,
},
cli.StringFlag{
Name: "white",
Value: "https://raw.githubusercontent.com/txthinking/pac/master/white.list",
Usage: "White list file path or http link.",
Destination: &whiteList,
},
cli.StringFlag{
Name: "whiteCIDR",
Value: "https://raw.githubusercontent.com/txthinking/pac/master/china_cidr.list",
Usage: "White list file path or http link.",
Destination: &whiteCIDR,
},
cli.StringFlag{
Name: "black",
Value: "https://raw.githubusercontent.com/txthinking/pac/master/black.list",
Usage: "Black list file path or http link.",
Destination: &blackList,
},
cli.StringFlag{
Name: "customize",
Value: "https://raw.githubusercontent.com/txthinking/pac/master/customize.map",
Usage: "Customized map file path or http link.",
Destination: &customizeMap,
},
cli.IntFlag{
Name: "cycle",
Value: 0,
Usage: "Cycle time(s) for updating white list and/or black list and/or customized map from the source.",
Destination: &cycle,
},
}
app.Action = func(c *cli.Context) error {
update()
return run()
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run() error {
r := mux.NewRouter()
r.Methods("GET").Path("/{mode}/{proxy}").HandlerFunc(pac)
r.Methods("GET").Path("/{mode}/{proxy}/pac.pac").HandlerFunc(pac)
n := negroni.New()
n.Use(negroni.NewRecovery())
n.Use(negroni.NewLogger())
n.UseHandler(r)
return http.ListenAndServe(listen, n)
}