Categorygithub.com/nabeken/go-proxyproto
repositorypackage
0.0.0-20190426043659-7d2e1e3f3cd2
Repository: https://github.com/nabeken/go-proxyproto.git
Documentation: pkg.go.dev

# README

go-proxyproto

Build Status

A Go library implementation of the PROXY protocol, versions 1 and 2, which provides, as per specification:

(...) a convenient way to safely transport connection information such as a client's address across multiple layers of NAT or TCP proxies. It is designed to require little changes to existing components and to limit the performance impact caused by the processing of the transported information.

Installation

$ go get -u github.com/nabeken/go-proxyproto

Usage

Server

Listen and upgrade the listener to the proxy-protocol aware listener:

ln, _ := net.Listen("tcp", "127.0.0.1:0")
pl: &Listener{
        Listener:           ln,
        ProxyHeaderTimeout: 3 * time.Minute,
}

conn, _ := s.pl.Accept()
log.Printf("accepted connection from %s to %s", conn.RemoteAddr().String(), conn.LocalAddr().String())

Client

As of today, this library doesn't provide a dialer so you need to write a proxy protocol header by yourself:

conn, _ := net.Dial("tcp", "127.0.0.1:12345")
hdr := &Header{
        Version:           1,
        Command:           PROXY,
        TransportProtocol: TCPv4,
        SrcAddr:           v4addr,
        DstAddr:           v4addr,
        SrcPort:           PORT,
        DstPort:           PORT,
}

// Write proxy protocol header to conn
hdr.WriteTo(conn)

Documentation

http://godoc.org/github.com/nabeken/go-proxyproto

Acknowledgement

This implemention is heavily based on https://github.com/pires/go-proxyproto and the its WIP pull request at https://github.com/pires/go-proxyproto/pull/2 which is derived from https://github.com/armon/go-proxyproto/blob/master/protocol.go.

My fork removed several incomplete implementations (e.g. timeout handling, UNIX socket support and TLV support).