fmt; fixed IP address dialer option for seclient

This commit is contained in:
Vladislav Yarmak 2021-03-27 02:48:07 +02:00
parent 9a35f96795
commit 1c4a8991bc
3 changed files with 58 additions and 23 deletions

31
fixed.go Normal file
View file

@ -0,0 +1,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)
}