mirror of
https://github.com/Snawoot/opera-proxy.git
synced 2025-09-02 02:30:21 +00:00
31 lines
673 B
Go
31 lines
673 B
Go
package dialer
|
|
|
|
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)
|
|
}
|