redialer

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package redialer provides a generic redialer for connection-like types in Go. It is useful when you need to access a connection from multiple goroutines. It helps to keep the reconnection logic in a single goroutine and provide protected access to the connection.

See netredialer subpackage for usage example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is the type that is returned from Redialer.Conn method.

func (*Conn) Get

func (c *Conn) Get() interface{}

Get returns the connected connection. You have to convert the returned value to the type your Dial function returns.

func (*Conn) SetClosed

func (c *Conn) SetClosed()

SetClosed tells Redialer that the connection is closed. You have to call this function after your code detected the connection is disconnected.

type Dialer

type Dialer interface {
	Addr() string // used in logs
	Dial() (conn io.Closer, err error)
	OnConnect(conn *Conn) error
}

Dialer is the interface passed to New function.

type Redialer

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

Redialer keeps connections connected.

func New

func New(d Dialer) *Redialer

New returns a new Redialer from Dialer.

func (*Redialer) Close

func (r *Redialer) Close() error

Close stops the Redialer and closes the connection if it is open.

func (*Redialer) Conn

func (r *Redialer) Conn() <-chan *Conn

Conn sends the connected connection on the returned channel. Only one Conn will be sent to the channel. If the Redialer is closed, the channel is closed.

func (*Redialer) Run

func (r *Redialer) Run()

Run the reconnection loop. Call this with a go statement.

Directories

Path Synopsis
Package amqpredialer provides a redialer for github.com/streadway/amqp.Conn.
Package amqpredialer provides a redialer for github.com/streadway/amqp.Conn.
Package netredialer provides a reconnecting net.Conn implementation.
Package netredialer provides a reconnecting net.Conn implementation.
Package smtpredialer provides a redialer for smtp.Client.
Package smtpredialer provides a redialer for smtp.Client.

Jump to

Keyboard shortcuts

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