Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsUdpSocket ¶
func IsUnixSocket ¶
Types ¶
type Client ¶
type Client interface { Connect() error Disconnect() error Command(command string, process Processor) error }
Client is the interface that wraps the basic socket client operations and hides the implementation details from the users.
Connect should prepare the connection.
Disconnect should stop any in-flight connections.
Command should send the actual data to the wire and pass any results to the processor function.
Implementations should return TCP, UDP or Unix ready sockets.
type Config ¶
type Config struct { Address string ConnectTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration TLSConf *tls.Config }
Config holds the network ip v4 or v6 address, port, Socket type(ip, tcp, udp, unix), timeout and TLS configuration for a Socket
type Processor ¶
Processor function passed to the Socket.Command function. It is passed by the caller to process a command's response line by line.
type Socket ¶
type Socket struct { Config // contains filtered or unexported fields }
Socket is the implementation of a socket client.
func New ¶
New returns a new pointer to a socket client given the socket type (IP, TCP, UDP, UNIX), a network address (IP/domain:port), a timeout and a TLS config. It supports both IPv4 and IPv6 address and reuses connection where possible.
func (*Socket) Command ¶
Command writes the command string to the connection and passed the response bytes line by line to the process function. It uses the timeout value from the Socket config and returns read, write and timeout errors if any. If a timeout occurs during the processing of the responses this function will stop processing and return a timeout error.
func (*Socket) Connect ¶
Connect connects to the Socket address on the named network. If the address is a domain name it will also perform the DNS resolution. Address like :80 will attempt to connect to the localhost. The config timeout and TLS config will be used.
func (*Socket) Disconnect ¶
Disconnect closes the connection. Any in-flight commands will be cancelled and return errors.