Categorygithub.com/fango6/proxyproto
modulepackage
1.0.2
Repository: https://github.com/fango6/proxyproto.git
Documentation: pkg.go.dev

# README

proxyproto

Go language to imeplementation of PROXY Protocol.

Supports version 1 & 2, TLV and CRC-32c (PP2_TYPE_CRC32C).

The official documentation: https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt

Usage

Server Side

package main

import (
	"log"
	"net"

	"github.com/fango6/proxyproto"
)

func main() {
	ln, err := net.Listen("tcp", "127.0.0.1:9090")
	if err != nil {
		log.Fatal(err)
	}

	proxyListener := proxyproto.NewListener(ln)
	for {
		conn, err := proxyListener.Accept()
		if err != nil {
			log.Println(err)
			continue
		}

		go server(conn)
	}
}

func server(conn net.Conn) {
	// do something
}

Client Side

package main

import (
	"log"
	"net"
	"time"

	"github.com/fango6/proxyproto"
)

func main() {
	h := &proxyproto.Header{
		Version:           proxyproto.Version2,
		Command:           proxyproto.CMD_PROXY,
		AddressFamily:     proxyproto.AF_INET,
		TransportProtocol: proxyproto.SOCK_STREAM,

		SrcAddr: &net.TCPAddr{
			IP:   net.IPv4(127, 0, 0, 1),
			Port: 12345,
		},
		DstAddr: &net.TCPAddr{
			IP:   net.IPv4(127, 0, 0, 1),
			Port: 56789,
		},
	}

	raw, err := h.Format()
	if err != nil {
		log.Println("err:", err)
		return
	}

	conn, err := net.DialTimeout("tcp", "127.0.0.1:9090", time.Second*5)
	if err != nil {
		log.Println("err:", err)
		return
	}
	n, err := h.WriteTo(conn)
	if err != nil || n != len(raw) {
		log.Println("write PROXY header to connection fail:", err)
	}
}

More usages in the example folder, please move to there.

# Packages

No description provided by the author

# Functions

CalcCRC32cChecksum calculate a CRC32c checksum value of the whole PROXY header.
ChecksumCRC32c CRC-32c checksum with header.
No description provided by the author
No description provided by the author
NewNoOpTLV create a PP2_TYPE_NOOP TLV group.
No description provided by the author
No description provided by the author
WithCRC32cChecksum validate CRC-32c checksum.
WithDisableProxyProto header is not read.
WithPostReadHeader want to do after reading header, such as logging.
WithReadHeaderTimeout read header with timeout.

# Constants

IPv4.
IPv6.
Unix.
Unspec.
Local.
Proxy.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
The following types have already been registered for the <type> field:.
UDP.
TCP.
Unspec.
Unknown value.
Version 1.
Version 2.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Conn wrap net.Conn, want to read and parse Proxy Protocol header, and so on.
No description provided by the author
No description provided by the author
TLV a Type-Length-Value group.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
PostReadHeader will be called after reading Proxy Protocol header.
PP2Type type of proxy protocol version 2.
TLVs TLV groups.
No description provided by the author
No description provided by the author