| 116 | } |
| 117 | |
| 118 | func (h *Http) SetProxy(proxyUrl string) *Http { |
| 119 | u, _ := url.Parse(proxyUrl) |
| 120 | switch u.Scheme { |
| 121 | case "https": |
| 122 | //log.Println("use proxy", u.Scheme) |
| 123 | h.HttpTransport.Proxy = http.ProxyURL(u) |
| 124 | case "http": |
| 125 | //log.Println("use proxy", u.Scheme) |
| 126 | h.HttpTransport.Proxy = http.ProxyURL(u) |
| 127 | case "socks5": |
| 128 | pwd, _ := u.User.Password() |
| 129 | auth := proxy.Auth{ |
| 130 | User: u.User.Username(), |
| 131 | Password: pwd, |
| 132 | } |
| 133 | |
| 134 | h.SetSocksProxy(u.Host, &auth) |
| 135 | |
| 136 | } |
| 137 | return h |
| 138 | |
| 139 | } |
| 140 | func (h *Http) SetSocksProxy(proxyUrl string, auth *proxy.Auth) *Http { |
| 141 | baseDialer := &net.Dialer{ |
| 142 | Timeout: 30 * time.Second, |