Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages multiple service connections. This struct is responsible for managing connections to different services identified by their addresses.
func NewClient ¶
func NewClient() *Client
NewClient creates a new instance of Client. It initializes the client with an empty map for managing services.
Returns: - *Client: Newly created instance of Client.
func (*Client) Close ¶ added in v0.23.24
Close closes all service connections managed by the client. It iterates over all services and closes each connection.
Returns: - error: Error, if any occurred during the closure of services.
func (*Client) Connect ¶
Connect establishes a service connection for a given address. It creates an instance of Service for network interactions.
Parameters: - address: string The TCP address to connect to. - nbInstances: ...int Optional parameter to specify the number of instances to create (default is 1).
Returns: - *Service: Instance of the Service for the specified address. - error: Error, if any occurred during the connection setup.
type Connection ¶ added in v0.23.24
type Connection struct {
// contains filtered or unexported fields
}
type Server ¶
type Server struct { Address string // Address to listen on // contains filtered or unexported fields }
Server represents a TCP server and contains information about the address it listens on and the underlying network listener.
func (*Server) Register ¶
Register is a method for registering API handlers with the server.
Parameters: - api: router.EndPoint - The EndPoint to register handlers from.
func (*Server) Start ¶
Start starts the TCP server, allowing it to accept incoming connections.
Returns: - error: An error if the server is already started or if there was an issue starting the server.
func (*Server) Stop ¶
Stop stops the TCP server.
Returns: - error: An error if the server is not active or if there was an issue stopping the server.
func (*Server) TCPHandler ¶ added in v0.23.24
TCPHandler handles TCP requests by unmarshalling, processing, and marshalling responses. It is responsible for converting raw byte data into a structured request, processing it using a router, and then returning the structured response as byte data. It handles errors at each step by returning an empty response in case of failure.
Parameters: - b: []byte Raw byte array representing a TCP request.
Returns: - []byte: Processed response as a byte array. Returns an empty response in case of errors.
type Service ¶ added in v0.23.24
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶ added in v0.23.24
NewService creates a new service instance. Initializes the service and starts connection cleanup routine.
Parameters: - address: string The TCP address of the server. - maxConns: int Maximum number of connections.
Returns: - *Service: New service instance.
func (*Service) Close ¶ added in v0.23.24
Close closes all TCP connections of the service. It stops the cleanup ticker and closes each active connection in the service.
Returns: - error: An error, if any occurred during the closure of connections.
func (*Service) Send ¶ added in v0.23.24
Send sends a request and waits for a response. Uses an available connection from the pool or scales up if needed.
Parameters: - exchange: *transport.Exchange Exchange object with request and response.
Returns: - *transport.Exchange: Updated exchange object with response.