github.com/AntonOrnatskyi/goproxy@v0.0.0-20190205095733-4526a9fa18b4/core/proxy/client/proxy.go (about) 1 // Package proxy provides support for a variety of protocols to proxy network 2 // data. 3 package client 4 5 import ( 6 "net" 7 "time" 8 9 socks5c "github.com/AntonOrnatskyi/goproxy/core/lib/socks5" 10 socks5 "github.com/AntonOrnatskyi/goproxy/core/proxy/client/socks5" 11 ) 12 13 // A Dialer is a means to establish a connection. 14 type Dialer interface { 15 // Dial connects to the given address via the proxy. 16 DialConn(conn *net.Conn, network, addr string) (err error) 17 } 18 19 // Auth contains authentication parameters that specific Dialers may require. 20 type Auth struct { 21 User, Password string 22 } 23 24 func SOCKS5(timeout time.Duration, auth *Auth) (Dialer, error) { 25 var a *socks5c.UsernamePassword 26 if auth != nil { 27 a = &socks5c.UsernamePassword{auth.User, auth.Password} 28 } 29 d := socks5.NewDialer(a, timeout) 30 return d, nil 31 }