-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (43 loc) · 925 Bytes
/
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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/cloudfoundry/go-socks5"
)
func main() {
server := createServer()
go func() {
addr := ":1080"
if err := server.ListenAndServe("tcp", addr); err != nil {
panic(err)
}
}()
waitForSignal()
}
func createServer() *socks5.Server {
// Set credentials
user := os.Getenv("PROXY_USER")
password := os.Getenv("PROXY_PASSWORD")
if user == "" {
panic("PROXY_USER env variable is not set")
}
if password == "" {
panic("PROXY_PASSWORD env variable is not set")
}
credentials := socks5.StaticCredentials{user: password}
// Create server
conf := &socks5.Config{Credentials: credentials}
server, err := socks5.New(conf)
if err != nil {
panic(err)
}
return server
}
func waitForSignal() {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
s := <-ch
log.Printf("Got signal: %v, exiting.", s)
}