/
paccmd.go
99 lines (84 loc) · 2.03 KB
/
paccmd.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
90
91
92
93
94
95
96
97
98
99
package pacutil
import (
"fmt"
"github.com/gookit/gcli/v3"
)
// refer links
// https://github.com/100apps/ipac
// https://zh.wikipedia.org/zh/%E4%BB%A3%E7%90%86%E8%87%AA%E5%8A%A8%E9%85%8D%E7%BD%AE
var PacTools = &gcli.Command{
Name: "pacgo",
// Hidden: true,
Desc: "pac tools",
Subs: []*gcli.Command{
PacServe,
GFWListCat,
GFWList2pac,
GFWListUpdate,
},
Aliases: []string{"pac"},
}
type PacOpts struct {
addr string
file string
gwUrl string
gwfile string
maxAge string
}
var pacOpts = PacOpts{}
var (
PacServe = &gcli.Command{
Name: "serve",
Desc: "start an pac serve",
Func: func(c *gcli.Command, args []string) error {
return startServer(pacOpts)
},
Config: func(c *gcli.Command) {
c.StrOpt(&pacOpts.addr, "addr", "a", ":11080", "server address")
c.StrOpt(&pacOpts.file, "file", "f", "", "pac file path")
c.Opt("file").Required = true
c.StrOpt(&pacOpts.gwfile, "gwfile", "", "", "gfw list file")
c.StrOpt(&pacOpts.maxAge, "max-age", "m", "31536000", "Cache Control max-age")
},
Examples: `
{$fullCmd} -f ./tmp/gfwlist-210422.pac
`,
}
GFWListUpdate = &gcli.Command{
Name: "gwup",
Desc: "start an pac serve",
Func: func(c *gcli.Command, args []string) error {
return nil
},
Aliases: []string{"upgw"},
}
// example: pacgo catgw -f tmp/gfwlist-210422.txt
GFWListCat = &gcli.Command{
Name: "catgw",
Desc: "decode gfw list content and print it",
Func: func(c *gcli.Command, args []string) error {
dst, err := DecodeGfwList(pacOpts.gwfile)
if err != nil {
return err
}
fmt.Println(string(dst))
return nil
},
Aliases: []string{"catgw"},
Config: func(c *gcli.Command) {
c.StrOpt(&pacOpts.gwfile, "file", "f", "", "gfw list file")
c.StrOpt(&pacOpts.gwUrl, "url", "u", "", "gfw list file url")
},
Examples: `
{$fullCmd} -f ./tmp/gfwlist-210422.txt
`,
}
GFWList2pac = &gcli.Command{
Name: "gwconv",
Desc: "convert gfw list to an pac file",
Func: func(c *gcli.Command, args []string) error {
return nil
},
Aliases: []string{"convgw"},
}
)