Scott Baker | ed4efab | 2020-01-13 19:12:25 -0800 | [diff] [blame] | 1 | // Copyright 2011 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package proxy |
| 6 | |
| 7 | import ( |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 8 | "context" |
Scott Baker | ed4efab | 2020-01-13 19:12:25 -0800 | [diff] [blame] | 9 | "net" |
| 10 | ) |
| 11 | |
| 12 | type direct struct{} |
| 13 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 14 | // Direct implements Dialer by making network connections directly using net.Dial or net.DialContext. |
Scott Baker | ed4efab | 2020-01-13 19:12:25 -0800 | [diff] [blame] | 15 | var Direct = direct{} |
| 16 | |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 17 | var ( |
| 18 | _ Dialer = Direct |
| 19 | _ ContextDialer = Direct |
| 20 | ) |
| 21 | |
| 22 | // Dial directly invokes net.Dial with the supplied parameters. |
Scott Baker | ed4efab | 2020-01-13 19:12:25 -0800 | [diff] [blame] | 23 | func (direct) Dial(network, addr string) (net.Conn, error) { |
| 24 | return net.Dial(network, addr) |
| 25 | } |
divyadesai | 1900913 | 2020-03-04 12:58:08 +0000 | [diff] [blame] | 26 | |
| 27 | // DialContext instantiates a net.Dialer and invokes its DialContext receiver with the supplied parameters. |
| 28 | func (direct) DialContext(ctx context.Context, network, addr string) (net.Conn, error) { |
| 29 | var d net.Dialer |
| 30 | return d.DialContext(ctx, network, addr) |
| 31 | } |