2024-11-03 15:17:29 +02:00
|
|
|
package dialer
|
2021-03-27 02:48:07 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type FixedDialer struct {
|
|
|
|
|
fixedAddress string
|
2021-03-30 15:50:57 +03:00
|
|
|
next ContextDialer
|
2021-03-27 02:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewFixedDialer(address string, next ContextDialer) *FixedDialer {
|
|
|
|
|
return &FixedDialer{
|
|
|
|
|
fixedAddress: address,
|
2021-03-30 15:50:57 +03:00
|
|
|
next: next,
|
2021-03-27 02:48:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|