forked from LN5400/NekoXProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1000 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
package main
import (
"encoding/base64"
"flag"
"log"
"net/http"
"os"
"time"
)
var proxyBaseDomain string
var proxyDomains []string
var client *http.Client
func main() {
listen := flag.String("l", getEnv("LISTEN", "127.0.0.1:26641"), "HttpProxy listen addr")
proxy := flag.String("p", getEnv("PROXY", ""), "Proxy URL (keep empty if you don't know)")
flag.Parse()
var ok bool
if proxy != nil && *proxy != "" {
ok = parseRelayProxy(base64.RawURLEncoding.EncodeToString([]byte(*proxy)))
} else {
log.Println("Getting public proxy...")
ok = parseRelayProxy(getPublicRelay())
}
if !ok {
log.Println("Failed to parse proxy.")
return
}
client = &http.Client{}
http.HandleFunc("/", relay)
server := &http.Server{
Addr: *listen,
WriteTimeout: 10 * time.Second,
}
log.Println("HTTP Proxy started at", *listen)
server.ListenAndServe()
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}