zrepl/internal/transport/tcp/connect_tcp.go
2024-10-18 19:21:17 +02:00

31 lines
594 B
Go

package tcp
import (
"context"
"net"
"github.com/zrepl/zrepl/internal/config"
"github.com/zrepl/zrepl/internal/transport"
)
type TCPConnecter struct {
Address string
dialer net.Dialer
}
func TCPConnecterFromConfig(in *config.TCPConnect) (*TCPConnecter, error) {
dialer := net.Dialer{
Timeout: in.DialTimeout,
}
return &TCPConnecter{in.Address, dialer}, nil
}
func (c *TCPConnecter) Connect(dialCtx context.Context) (transport.Wire, error) {
conn, err := c.dialer.DialContext(dialCtx, "tcp", c.Address)
if err != nil {
return nil, err
}
return conn.(*net.TCPConn), nil
}