Is that possible use v2ray-core as library in golang as http.Transport ? #2527
Unanswered
ah-its-andy
asked this question in
Q&A
Replies: 1 comment
-
like this package main
import (
"fmt"
"golang.org/x/net/proxy"
"io/ioutil"
"net/http"
)
func NewSocksDialer(addr string) (proxy.Dialer, error) {
return proxy.SOCKS5("tcp", addr, nil, proxy.Direct)
}
func main() {
dialer, err := NewSocksDialer("127.0.0.1:1080")
if err != nil {
fmt.Println(err.Error())
return
}
// create a socks5 dialer
// setup a http client
httpTransport := &http.Transport{Dial: dialer.Dial}
httpClient := &http.Client{Transport: httpTransport}
// set our socks5 as the dialer
if resp, err := httpClient.Get("https://www.google.com"); err != nil {
fmt.Println(err.Error())
return
} else {
defer resp.Body.Close()
if bs, err := ioutil.ReadAll(resp.Body); err == nil {
fmt.Println(string(bs))
} else {
fmt.Println(err.Error())
}
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am think about to use v2ray-core as a proxy server for expose some internal service api to the public network securely. I use v2ray docker to provide local http proxy server, and use a http.Transport in http.Client to connect with local proxy server, then local proxy server connect the remote proxy server, reach some internal service api finally.
I want to make it more simple by using v2ray-core to build http.Transport directly. How to make this work?
Beta Was this translation helpful? Give feedback.
All reactions