sender

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosed   = errors.New("connection closed")
	ErrFailedToSend = errors.New("failed to send message")
)

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithCloseListener

func WithCloseListener(f func(error), cancel ...*func()) Option

WithCloseListener sets the function to call when the connection is closed. If cancel is provided, it will be populated with a function that can be used to remove the listener.

func WithSendTimeout

func WithSendTimeout(timeout time.Duration) Option

WithSendTimeout sets the timeout for sending messages.

func WithURL

func WithURL(url string) Option

WithURL sets the target URL for the connection. This option is required.

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

Sender is a simple connection to an external service. It is safe for concurrent use.

func New

func New(opts ...Option) (*Sender, error)

New creates a new Sender. The Sender is not connected to the remote service until Dial() is called. The Sender is safe for concurrent use. The option WithURL is required.

func (*Sender) Close

func (s *Sender) Close() error

Close closes the connection to the remote service. This method is idempotent.

func (*Sender) Dial

func (s *Sender) Dial() error

Dial connects the Sender to the remote service. This method is idempotent.

func (*Sender) ProcessWRP

func (s *Sender) ProcessWRP(ctx context.Context, msg wrp.Message) error

ProcessWRP sends a WRP message to the remote service. The context is used to set a timeout for the send operation. If the context is canceled, the send operation will fail with a context.Canceled error. If the connection is closed, the send operation will fail with ErrConnClosed. If the send operation fails for any other reason, the error will be wrapped with ErrFailedToSend. ProcessWRP will never return wrp.ErrNotHandled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL