func (p *Conn) RemoteAddr() net.Addr {
	p.checkPrefixOnce()
	if p.srcAddr != nil && !p.useConnAddr {
		return p.srcAddr
	}
	return p.conn.RemoteAddr()
}
RemoteAddr returns the address of the client if the proxy
protocol is being used, otherwise just returns the address of
the socket peer. If there is an error parsing the header, the
address of the client is not returned, and the socket is closed.
Once implication of this is that the call could block if the
client is slow. Using a Deadline is recommended if this is called
before Read()
package proxyproto
import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io"
	"log"
	"net"
	"strconv"
	"strings"
	"sync"
	"time"
)
var (
	prefix    = []byte("PROXY ")
	prefixLen = len(prefix)
	ErrInvalidUpstream = errors.New("upstream connection address not trusted for PROXY information")
)
type SourceChecker func(net.Addr) (bool, error)
type Listener struct {
	Listener           net.Listener
	ProxyHeaderTimeout time.Duration
	SourceCheck        SourceChecker
	UnknownOK          bool  
}
type Conn struct {
	bufReader          *bufio.Reader
	conn               net.Conn
	dstAddr            *net.TCPAddr
	srcAddr            *net.TCPAddr
	useConnAddr        bool
	once               sync.Once
	proxyHeaderTimeout time.Duration
	unknownOK          bool
}
func (p *Listener) Accept() (net.Conn, error) {
	for {
		conn, err := p.Listener.Accept()
		if err != nil {
			return nil, err
		}
		var useConnAddr bool
		if p.SourceCheck != nil {
			allowed, err := p.SourceCheck(conn.RemoteAddr())
			if err != nil {
				if err == ErrInvalidUpstream {
					conn.Close()
					continue
				}
				return nil, err
			}
			if !allowed {
				useConnAddr = true
			}
		}
		newConn := NewConn(conn, p.ProxyHeaderTimeout)
		newConn.useConnAddr = useConnAddr
		newConn.unknownOK = p.UnknownOK
		return newConn, nil
	}
}
func (p *Listener) Close() error {
	return p.Listener.Close()
}
func (p *Listener) Addr() net.Addr {
	return p.Listener.Addr()
}
func NewConn(conn net.Conn, timeout time.Duration) *Conn {
	pConn := &Conn{
		bufReader:          bufio.NewReader(conn),
		conn:               conn,
		proxyHeaderTimeout: timeout,
	}
	return pConn
}
func (p *Conn) Read(b []byte) (int, error) {
	var err error
	p.once.Do(func() { err = p.checkPrefix() })
	if err != nil {
		return 0, err
	}
	return p.bufReader.Read(b)
}
func (p *Conn) ReadFrom(r io.Reader) (int64, error) {
	if rf, ok := p.conn.(io.ReaderFrom); ok {
		return rf.ReadFrom(r)
	}
	return io.Copy(p.conn, r)
}
func (p *Conn) WriteTo(w io.Writer) (int64, error) {
	var err error
	p.once.Do(func() { err = p.checkPrefix() })
	if err != nil {
		return 0, err
	}
	return p.bufReader.WriteTo(w)
}
func (p *Conn) Write(b []byte) (int, error) {
	return p.conn.Write(b)
}
func (p *Conn) Close() error {
	return p.conn.Close()
}
func (p *Conn) LocalAddr() net.Addr {
	p.checkPrefixOnce()
	if p.dstAddr != nil && !p.useConnAddr {
		return p.dstAddr
	}
	return p.conn.LocalAddr()
}