tunnel

package
v2.0.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func (Connection) Release

func (rc Connection) Release()

Release closes the connection and notifies the pool about the need to create a new connection. Call this method when you no longer need the connection, this is very important to keep the pool!

type ConnectionsPool

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

func NewConnectionsPool

func NewConnectionsPool(
	ctx context.Context,
	remoteAddr string,
	size uint,
	opts ...ConnectionsPoolOption,
) (ConnectionsPool, func())

NewConnectionsPool creates a new pool of connections to the remote server. The pool will create connections in the background and will keep the total number of connections equal to the size parameter. The pool will create new connections when the connection will be released using the Connection.Release method.

To close the pool and release all connections, call the returned cleanup function (it will close all connections, stop all goroutines and empty the pool of connections).

func (ConnectionsPool) Get

func (cp ConnectionsPool) Get(optionalCtx ...context.Context) (Connection, bool)

Get returns an active connection from the pool. If the pool is empty, the method will block until a new connection is established and added to the pool, or the context is canceled.

Use the 2nd return value to check if the connection was successfully received.

type ConnectionsPoolOption

type ConnectionsPoolOption func(*ConnectionsPool)

ConnectionsPoolOption allows you to configure the ConnectionsPool during creation.

func WithConnectionsPoolDialer

func WithConnectionsPoolDialer(dialer func(context.Context, string, string) (net.Conn, error)) ConnectionsPoolOption

WithConnectionsPoolDialer sets the dialer for the ConnectionsPool. By default, the pool uses the net.Dialer.DialContext method. Useful for testing purposes.

func WithConnectionsPoolErrorsHandler

func WithConnectionsPoolErrorsHandler(fn func(error)) ConnectionsPoolOption

WithConnectionsPoolErrorsHandler sets the error handler for the ConnectionsPool.

type Ngrok

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

func NewNgrok

func NewNgrok(authToken string, opts ...NgrokOption) *Ngrok

NewNgrok creates a new Ngrok instance with the given auth token and options.

func (*Ngrok) Close

func (n *Ngrok) Close() error

func (*Ngrok) Expose

func (n *Ngrok) Expose(ctx context.Context, localPort uint16) (string, error)

type NgrokOption

type NgrokOption func(*Ngrok)

NgrokOption is a functional option for the Ngrok instance.

func WithNgrokLogger

func WithNgrokLogger(log *zap.Logger) NgrokOption

WithNgrokLogger sets the logger for the Ngrok instance.

type Tunneler

type Tunneler interface {
	// Close the tunnel.
	Close() error

	// Expose starts a tunnel to the local port and returns the public URL. To close/stop the tunnel, call Close.
	Expose(ctx context.Context, localPort uint16) (string, error)
}

Jump to

Keyboard shortcuts

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