Prepare for a proxyless mode.

This commit is contained in:
Kavin 2022-06-23 22:02:51 +01:00
parent 2b0fa64656
commit a761ae1031
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
3 changed files with 13 additions and 5 deletions

View File

@ -0,0 +1,6 @@
services:
ryd-proxy:
image: 1337kavin/ryd-proxy:latest
restart: unless-stopped
ports:
- "127.0.0.1:3000:3000"

View File

@ -9,5 +9,7 @@ services:
restart: unless-stopped
depends_on:
- tor-proxy
environment:
- PROXY=socks5://tor-proxy:5566
ports:
- "127.0.0.1:3000:3000"

10
main.go
View File

@ -20,13 +20,13 @@ var client *http.Client
func main() {
proxy := os.Getenv("PROXY")
var httpProxy func(*http.Request) (*url.URL, error)
if proxy == "" {
proxy = "socks5://tor-proxy:5566"
if proxy != "" {
proxyUrl, _ := url.Parse(proxy)
httpProxy = http.ProxyURL(proxyUrl)
}
proxyUrl, _ := url.Parse(proxy)
client = &http.Client{
Transport: &http.Transport{
Dial: (&net.Dialer{
@ -41,7 +41,7 @@ func main() {
MaxConnsPerHost: 0,
MaxIdleConnsPerHost: 10,
MaxIdleConns: 0,
Proxy: http.ProxyURL(proxyUrl),
Proxy: httpProxy,
},
}