proxy

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package proxy implements a proxy object that can take connections from a listener and forward them to a backend through a configurable dialer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialer

type Dialer func() (net.Conn, error)

Dialer represents a function that can dial a backend/destination for forwarding connections.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger is used by this package to log messages

type Proxy

type Proxy struct {
	// Listener to accept connetions on.
	Listener net.Listener
	// ConnectTimeout after which connections are terminated.
	ConnectTimeout time.Duration
	// Dial function to reach backend to forward connections to.
	Dial Dialer
	// Logger is used to log information messages about connections, errors.
	Logger Logger
	// contains filtered or unexported fields
}

Proxy will take incoming connections from a listener and forward them to a backend through the given dialer.

func New

func New(listener net.Listener, timeout time.Duration, dial Dialer, logger Logger) *Proxy

New creates a new proxy.

func (*Proxy) Accept

func (p *Proxy) Accept()

Accept incoming connections and spawn Go routines to handle them and forward the data to the backend. Will stop accepting connections if Shutdown() is called. Run this in a Goroutine, call Wait() to block on proxy shutdown/connection drain.

func (*Proxy) Shutdown

func (p *Proxy) Shutdown()

Shutdown tells the proxy to close the listener & stop accepting connections.

func (*Proxy) Wait

func (p *Proxy) Wait()

Wait until the proxy is shut down (listener closed, connections drained). This function will block even if the proxy isn't in the accept loop yet, so it's safe to concurrently run Accept() in a Goroutine and then immediately call Wait().

Jump to

Keyboard shortcuts

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