Documentation
¶
Index ¶
- Variables
- type Connection
- func (c *Connection) Addr() string
- func (c *Connection) Close() error
- func (c *Connection) CloseCtx(ctx context.Context) error
- func (c *Connection) Connect() error
- func (c *Connection) ConnectCtx(ctx context.Context) error
- func (c *Connection) Done() <-chan struct{}
- func (c *Connection) RejectMessage(rejectedMessage *iso8583.Message, rejectionError error) error
- func (c *Connection) Reply(message *iso8583.Message) error
- func (c *Connection) Send(message *iso8583.Message, options ...Option) (*iso8583.Message, error)
- func (c *Connection) SetOptions(options ...Option) error
- func (c *Connection) SetStatus(status Status)
- func (c *Connection) Status() Status
- func (c *Connection) Write(p []byte) (int, error)
- type ConnectionFactoryFunc
- type FilterFunc
- type MessageLengthReader
- type MessageLengthWriter
- type MessageReader
- type MessageWriter
- type Option
- func ClientCert(cert, key string) Option
- func ConnectTimeout(d time.Duration) Option
- func ConnectionClosedHandler(handler func(c *Connection)) Option
- func ConnectionEstablishedHandler(handler func(c *Connection)) Option
- func ErrorHandler(h func(err error)) Option
- func IdleTime(d time.Duration) Option
- func InboundMessageHandler(handler func(c *Connection, message *iso8583.Message)) Option
- func OnClose(h func(c *Connection) error) Option
- func OnCloseCtx(h func(ctx context.Context, c *Connection) error) Option
- func OnConnect(h func(c *Connection) error) Option
- func OnConnectCtx(h func(ctx context.Context, c *Connection) error) Option
- func PingHandler(handler func(c *Connection)) Option
- func ReadTimeout(d time.Duration) Option
- func ReadTimeoutHandler(handler func(c *Connection)) Option
- func RootCAs(file ...string) Option
- func SendTimeout(d time.Duration) Option
- func SetMessageReader(r MessageReader) Option
- func SetMessageWriter(w MessageWriter) Option
- func SetRequestIDGenerator(g RequestIDGenerator) Option
- func SetTLSConfig(cfg func(*tls.Config)) Option
- type Options
- type Pool
- func (p *Pool) Close() error
- func (p *Pool) CloseCtx(ctx context.Context) error
- func (p *Pool) Connect() error
- func (p *Pool) ConnectCtx(ctx context.Context) error
- func (p *Pool) Connections() []*Connection
- func (p *Pool) Done() <-chan struct{}
- func (p *Pool) Get() (*Connection, error)
- func (p *Pool) IsDegraded() bool
- func (p *Pool) IsUp() bool
- type PoolOption
- type PoolOptions
- type RejectedMessageError
- type RequestIDGenerator
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnectionClosed = errors.New("connection closed") ErrSendTimeout = errors.New("message send timeout") )
var ErrNoConnections = errors.New("no connections (online)")
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { Opts Options // contains filtered or unexported fields }
Connection represents an ISO 8583 Connection. Connection may be used by multiple goroutines simultaneously.
func New ¶
func New(addr string, spec *iso8583.MessageSpec, mlReader MessageLengthReader, mlWriter MessageLengthWriter, options ...Option) (*Connection, error)
New creates and configures Connection. To establish network connection, call `Connect()`.
func NewFrom ¶
func NewFrom(conn io.ReadWriteCloser, spec *iso8583.MessageSpec, mlReader MessageLengthReader, mlWriter MessageLengthWriter, options ...Option) (*Connection, error)
NewFrom accepts conn (net.Conn, or any io.ReadWriteCloser) which will be used as a transport for the returned Connection. Returned Connection is ready to be used for message sending and receiving
func (*Connection) Addr ¶ added in v0.1.6
func (c *Connection) Addr() string
Addr returns the remote address of the connection
func (*Connection) Close ¶
func (c *Connection) Close() error
Close waits for pending requests to complete and then closes network connection with ISO 8583 server
func (*Connection) CloseCtx ¶ added in v0.8.1
func (c *Connection) CloseCtx(ctx context.Context) error
CloseCtx waits for pending requests to complete and then closes network connection with ISO 8583 server
func (*Connection) Connect ¶
func (c *Connection) Connect() error
Connect establishes the connection to the server using configured Addr
func (*Connection) ConnectCtx ¶ added in v0.8.1
func (c *Connection) ConnectCtx(ctx context.Context) error
ConnectCtx establishes the connection to the server using configured Addr
func (*Connection) Done ¶
func (c *Connection) Done() <-chan struct{}
func (*Connection) RejectMessage ¶ added in v0.8.0
func (c *Connection) RejectMessage(rejectedMessage *iso8583.Message, rejectionError error) error
RejectMessage returns RejectedMessageError to the response err channel that corresponds to the ID of the rejectedMessage. This method is used to reject messages that were sent to the network and response was received, but response code indicates that message was rejected. In many cases, such rejection happens outside of normal request-response flow, so it is not possible to return response to the caller. In such cases, RejectedMessageError is returned. It's up to the implementation to decide when to call RejectMessage and when to return RejectedMessageError.
func (*Connection) Reply ¶
func (c *Connection) Reply(message *iso8583.Message) error
Reply sends the message and does not wait for a reply to be received. Any reply received for message send using Reply will be handled with unmatchedMessageHandler
func (*Connection) Send ¶
Send sends message and waits for the response. You can pass optional parameters to the Send method using functional options pattern. Currently, only SendTimeout option is supported. Using it, you can set specific send timeout value for the `Send` method call. Example:
conn.Send(msg, connection.SendTimeout(5 * time.Second))
func (*Connection) SetOptions ¶
func (c *Connection) SetOptions(options ...Option) error
SetOptions sets connection options
func (*Connection) SetStatus ¶ added in v0.3.0
func (c *Connection) SetStatus(status Status)
SetStatus sets the connection status
func (*Connection) Status ¶ added in v0.3.0
func (c *Connection) Status() Status
Status returns the connection status
func (*Connection) Write ¶ added in v0.5.0
func (c *Connection) Write(p []byte) (int, error)
Write writes data directly to the connection. It is crucial to note that the Write operation is atomic in nature, meaning it completes in a single uninterrupted step. When writing data, the entire message—including its header and any other components—should be written in one go. Splitting a single message into multiple Write calls is dangerous, as it could lead to unexpected behavior or errors.
type ConnectionFactoryFunc ¶ added in v0.3.0
type ConnectionFactoryFunc func(addr string) (*Connection, error)
type FilterFunc ¶ added in v0.3.0
type FilterFunc func(*Connection) bool
FilterFunc is a function to filter connections
type MessageLengthReader ¶
MessageLengthReader reads message header from the r and returns message length
type MessageLengthWriter ¶
MessageLengthWriter writes message header with encoded length into w
type MessageReader ¶ added in v0.4.0
type MessageWriter ¶ added in v0.4.0
type Option ¶
func ClientCert ¶
func ConnectTimeout ¶ added in v0.1.6
ConnectTimeout sets an SendTimeout option
func ConnectionClosedHandler ¶ added in v0.1.3
func ConnectionClosedHandler(handler func(c *Connection)) Option
ConnectionClosedHandler sets a ConnectionClosedHandler option
func ConnectionEstablishedHandler ¶ added in v0.3.0
func ConnectionEstablishedHandler(handler func(c *Connection)) Option
func ErrorHandler ¶ added in v0.1.5
ErrorHandler sets an ErrorHandler option in many cases err will be an instance of the `SafeError` for more details: https://github.com/moov-io/iso8583/pull/185
func InboundMessageHandler ¶
func InboundMessageHandler(handler func(c *Connection, message *iso8583.Message)) Option
InboundMessageHandler sets an InboundMessageHandler option
func OnClose ¶ added in v0.3.1
func OnClose(h func(c *Connection) error) Option
func OnCloseCtx ¶ added in v0.8.1
func OnCloseCtx(h func(ctx context.Context, c *Connection) error) Option
func OnConnect ¶ added in v0.3.0
func OnConnect(h func(c *Connection) error) Option
OnConnect sets a callback that will be synchronously called when connection is established. If it returns error, then connections will be closed and re-connect will be attempted
func OnConnectCtx ¶ added in v0.8.1
func OnConnectCtx(h func(ctx context.Context, c *Connection) error) Option
OnConnectCtx sets a callback that will be synchronously called when connection is established. If it returns error, then connections will be closed and re-connect will be attempted
func PingHandler ¶
func PingHandler(handler func(c *Connection)) Option
PingHandler sets a PingHandler option
func ReadTimeout ¶ added in v0.1.4
ReadTimeout sets an ReadTimeout option
func ReadTimeoutHandler ¶ added in v0.1.4
func ReadTimeoutHandler(handler func(c *Connection)) Option
ReadTimeoutHandler sets a ReadTimeoutHandler option
func SetMessageReader ¶ added in v0.4.0
func SetMessageReader(r MessageReader) Option
SetMessageReader sets a MessageReader option
func SetMessageWriter ¶ added in v0.4.0
func SetMessageWriter(w MessageWriter) Option
SetMessageWriter sets a MessageWriter option
func SetRequestIDGenerator ¶ added in v0.3.2
func SetRequestIDGenerator(g RequestIDGenerator) Option
RequestIDGenerator sets a RequestIDGenerator option
func SetTLSConfig ¶
type Options ¶
type Options struct { // ConnectTimeout sets the timeout for establishing new connections. // The default is 10 seconds. ConnectTimeout time.Duration // SendTimeout sets the timeout for a Send operation. // The default is 30 seconds. SendTimeout time.Duration // IdleTime is the period at which the client will be sending ping // message to the server. // The default is 5 seconds. IdleTime time.Duration // ReadTimeout is the maximum time between read events before the // ReadTimeoutHandler is called. // The default is 60 seconds. ReadTimeout time.Duration // PingHandler is called when no message was sent during idle time // it should be safe for concurrent use PingHandler func(c *Connection) // ReadTimeoutHandler is called when no message has been received within // the ReadTimeout interval ReadTimeoutHandler func(c *Connection) // InboundMessageHandler is called when a message from the server is // received and no matching request for it was found. // InboundMessageHandler should be safe for concurrent use. Use it // for the following use cases: // * to log timed out responses // * to handle network management messages (echo, heartbeat, etc.) InboundMessageHandler func(c *Connection, message *iso8583.Message) // ConnectionClosedHandlers is called after connection is closed by us, // by the server or when there are network errors during network // read/write ConnectionClosedHandlers []func(c *Connection) // ConnectionEstablishedHandler is called when connection is // established with the server ConnectionEstablishedHandler func(c *Connection) TLSConfig *tls.Config // ErrorHandler is called in a goroutine with the errors that can't be // returned to the caller ErrorHandler func(err error) // If both OnConnect and OnConnectCtx are set, OnConnectCtx will be used // OnConnect is called synchronously when a connection is established OnConnect func(c *Connection) error // OnConnectCtx is called synchronously when a connection is established OnConnectCtx func(ctx context.Context, c *Connection) error // If both OnClose and OnCloseCtx are set, OnCloseCtx will be used // OnClose is called synchronously before a connection is closed OnClose func(c *Connection) error // OnCloseCtx is called synchronously before a connection is closed OnCloseCtx func(ctx context.Context, c *Connection) error // RequestIDGenerator is used to generate a unique identifier for a request // so that responses from the server can be matched to the original request. RequestIDGenerator RequestIDGenerator // MessageReader is used to read a message from the connection // if set, connection's MessageLengthReader will be ignored MessageReader MessageReader // MessageWriter is used to write a message to the connection // if set, connection's MessageLengthWriter will be ignored MessageWriter MessageWriter }
func GetDefaultOptions ¶
func GetDefaultOptions() Options
type Pool ¶ added in v0.3.0
type Pool struct { Factory ConnectionFactoryFunc Addrs []string Opts PoolOptions // contains filtered or unexported fields }
func NewPool ¶ added in v0.3.0
func NewPool(factory ConnectionFactoryFunc, addrs []string, options ...PoolOption) (*Pool, error)
Pool - provides connections to the clients. It removes the connection from the pool if it was closed and in the background tries to create and etablish new connection so the pool will be full.
func (*Pool) Connect ¶ added in v0.3.0
Connect creates poll of connections by calling Factory method and connect them all
func (*Pool) ConnectCtx ¶ added in v0.8.1
Connect creates poll of connections by calling Factory method and connect them all
func (*Pool) Connections ¶ added in v0.3.0
func (p *Pool) Connections() []*Connection
Connections returns copy of all connections from the pool
func (*Pool) Get ¶ added in v0.3.0
func (p *Pool) Get() (*Connection, error)
Get returns filtered connection from the pool
func (*Pool) IsDegraded ¶ added in v0.3.0
IsDegraded returns true if pool is not full
type PoolOption ¶ added in v0.3.0
type PoolOption func(*PoolOptions) error
func PoolConnectionsFilter ¶ added in v0.3.0
func PoolConnectionsFilter(f func(*Connection) bool) PoolOption
func PoolErrorHandler ¶ added in v0.3.0
func PoolErrorHandler(h func(err error)) PoolOption
func PoolMaxReconnectWait ¶ added in v0.6.0
func PoolMaxReconnectWait(rw time.Duration) PoolOption
func PoolMinConnections ¶ added in v0.3.0
func PoolMinConnections(n int) PoolOption
func PoolReconnectWait ¶ added in v0.3.0
func PoolReconnectWait(rw time.Duration) PoolOption
type PoolOptions ¶ added in v0.3.0
type PoolOptions struct { // ReconnectWait sets the time to wait after first re-connect attempt // The default is 5 seconds ReconnectWait time.Duration // MaxReconnectWait specifies the maximum duration to wait between // reconnection attempts, serving as the upper bound for exponential // backoff. // A zero value means no exponential backoff and ReconnectWait is used // for each retry. // The default is 0. MaxReconnectWait time.Duration // ErrorHandler is called in a goroutine with the errors that can't be // returned to the caller. Don't block in this function as it will // block the connection pool Close() method. ErrorHandler func(err error) // MinConnections is the number of connections required to be established when // we connect the pool. // A zero value means that Pool will not return error on `Connect` and will // try to connect to all the addresses in the pool. // The default is 1. MinConnections int // ConnectionsFilter is a function to filter connections in the pool // when Get() is called ConnectionsFilter func(*Connection) bool }
func GetDefaultPoolOptions ¶ added in v0.3.0
func GetDefaultPoolOptions() PoolOptions
type RejectedMessageError ¶ added in v0.8.0
type RejectedMessageError struct {
Err error
}
RejectedMessageError is returned to the `Send` method caller when message is rejected.
func (*RejectedMessageError) Error ¶ added in v0.8.0
func (e *RejectedMessageError) Error() string
func (*RejectedMessageError) Unwrap ¶ added in v0.8.0
func (e *RejectedMessageError) Unwrap() error
type RequestIDGenerator ¶ added in v0.3.2
RequestIDGenerator is an interface that generates a unique identifier for a request so that responses from the server can be matched to the original request.