-
Notifications
You must be signed in to change notification settings - Fork 62
/
fixed.go
31 lines (25 loc) · 671 Bytes
/
fixed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"context"
"net"
)
type FixedDialer struct {
fixedAddress string
next ContextDialer
}
func NewFixedDialer(address string, next ContextDialer) *FixedDialer {
return &FixedDialer{
fixedAddress: address,
next: next,
}
}
func (d *FixedDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
_, port, err := net.SplitHostPort(address)
if err != nil {
return nil, err
}
return d.next.DialContext(ctx, network, net.JoinHostPort(d.fixedAddress, port))
}
func (d *FixedDialer) Dial(network, address string) (net.Conn, error) {
return d.DialContext(context.Background(), network, address)
}