forked from cta08403/goagent-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (66 loc) · 1.7 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
package main
import (
"flag"
"fmt"
"net"
"os"
"runtime"
"strings"
"./httpproxy"
"./httpproxy/helpers"
)
var (
version = "r9999"
http2rev = "?????"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "-version" {
fmt.Print(version)
return
}
helpers.SetFlagsIfAbsent(map[string]string{
"logtostderr": "true",
"v": "2",
})
flag.Parse()
gover := strings.Split(strings.TrimPrefix(runtime.Version(), "devel +"), " ")[0]
switch runtime.GOARCH {
case "386", "amd64":
helpers.SetConsoleTitle(fmt.Sprintf("GoProxy %s (go/%s)", version, gover))
}
fmt.Fprintf(os.Stderr, `------------------------------------------------------
GoProxy Version : %s (go/%s http2/%s %s/%s)`,
version, gover, http2rev, runtime.GOOS, runtime.GOARCH)
for profile, config := range httpproxy.Config {
if !config.Enabled {
continue
}
addr := config.Address
if ip, port, err := net.SplitHostPort(addr); err == nil {
switch ip {
case "", "0.0.0.0", "::":
if ips, err := helpers.LocalInterfaceIPs(); err == nil && len(ips) > 0 {
ip = ips[len(ips)-1].String()
}
}
addr = net.JoinHostPort(ip, port)
}
fmt.Fprintf(os.Stderr, `
GoProxy Profile : %s
Listen Address : %s
Enabled Filters : %v`,
profile,
addr,
fmt.Sprintf("%s|%s|%s", strings.Join(config.RequestFilters, ","), strings.Join(config.RoundTripFilters, ","), strings.Join(config.ResponseFilters, ",")))
for _, fn := range config.RoundTripFilters {
switch fn {
case "autoproxy":
fmt.Fprintf(os.Stderr, `
Pac Server : http://%s/proxy.pac`, addr)
}
}
go httpproxy.ServeProfile(profile)
}
fmt.Fprintf(os.Stderr, "\n------------------------------------------------------\n")
select {}
}