forked from usam123/eproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.go
More file actions
60 lines (50 loc) · 985 Bytes
/
proxy.go
File metadata and controls
60 lines (50 loc) · 985 Bytes
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
package main
import (
"log"
"net"
"net/http"
_ "net/http/pprof"
"net/url"
"time"
"golang.org/x/net/proxy"
)
const (
DefaultTimeout = 20 * time.Second
)
func main() {
conf, target_url, socks5, err := Init()
if err != nil {
ErrorFunc(err.Error())
}
u, err := url.Parse(target_url)
if err != nil {
ErrorFunc(err.Error())
}
client := &http.Client{
Timeout: DefaultTimeout,
}
if socks5 != "" {
dialer, err := proxy.SOCKS5("tcp", socks5, nil, proxy.Direct)
if err != nil {
ErrorFunc(err.Error())
}
httpTransport := &http.Transport{}
httpTransport.Dial = dialer.Dial
client.Transport = httpTransport
log.Println("socks5: ", socks5)
}
var server net.Listener
server, err = net.Listen("tcp", ":80")
log.Println("Listening on:80")
if err != nil {
ErrorFunc(err.Error())
}
for {
conn, err := server.Accept()
if err != nil {
log.Println("Error server.Accept:", err.Error())
continue
}
go Handler(conn, client, u, conf)
}
}