proxyprotocol

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 161

README

go-proxyprotocol

PROXY protocol implementation in Go.

Usage

import

import (
	proxyprotocol "github.com/blacktear23/go-proxyprotocol"
)

basic usage

// Create listener
l, err := net.Listen("tcp", "...")

// Wrap listener as PROXY protocol listener
ppl, err := proxyprotocol.NewListener(l, "*", 5)

for {
    conn, err := ppl.Accept()
    if err != nil {
        // PROXY protocol related errors can be output by log and
        // continue accept next one.
        if proxyprotocol.IsProxyProtocolError(err) {
            log.Errorf("PROXY protocol error: %s", err.Error())
            continue
        }
        panic(err)
    }
    go processConn(conn)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProxyProtocolV1HeaderInvalid = errors.New("PROXY Protocol v1 header is invalid")
	ErrProxyProtocolV2HeaderInvalid = errors.New("PROXY Protocol v2 header is invalid")
	ErrHeaderReadTimeout            = errors.New("Header read timeout")
)

Functions

func IsProxyProtocolError

func IsProxyProtocolError(err error) bool

func NewListener

func NewListener(listener net.Listener, allowedIPs string, headerReadTimeout int) (net.Listener, error)

Create new PROXY protocol listener * listener is basic listener for TCP * allowedIPs is protocol allowed addresses or CIDRs split by `,` if use '*' means allow any address * headerReadTimeout is timeout for PROXY protocol header read

Types

This section is empty.

Jump to

Keyboard shortcuts

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