Documentation
¶
Overview ¶
Example ¶
f, _ := forwarded.Parse("for=192.0.2.43, for=\"[2001:db8:cafe::17]\", for=unknown") fmt.Printf("%s\n", f) fmt.Printf("% s\n", f) // With spaces
Output: for=192.0.2.43,for=[2001:db8:cafe::17],for=unknown for=192.0.2.43, for=[2001:db8:cafe::17], for=unknown
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidLength = errors.New("invalid length")
View Source
var ErrNoHeaderFound = errors.New("no forwarded header found")
ErrNoHeaderFound is an error when no forwarded header found.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct { By string `json:"by,omitempty"` For string `json:"for,omitempty"` Host string `json:"host,omitempty"` Proto string `json:"proto,omitempty"` }
Element is a step of proxy.
func (*Element) StringSpace ¶
StringSpace returns a string value with spaces.
type Forwarded ¶
type Forwarded []*Element
Forwarded is a slice of each step.
func FromX ¶
Example ¶
f, _ := forwarded.FromX( forwarded.For("203.0.113.1, 203.0.113.2"), forwarded.Host("example.com, example.org"), ) fmt.Println("Forwarded: " + f.String())
Output: Forwarded: for=203.0.113.1;host=example.com,for=203.0.113.2;host=example.org
func Parse ¶
func Parse(forwarded string, opts ...ParseOption) (Forwarded, error)
Parse forwarded field
func ParseHeader ¶
func ParseHeader(header http.Header, opts ...ParseOption) (Forwarded, error)
ParseHeader parse forwarded header fields
func (Forwarded) StringSpace ¶
StringSpace returns a string value with spaces.
type ParseOption ¶
type ParseOption func(*parser)
ParseOption is a option to configure parser.
func InitialCapacity ¶
func InitialCapacity(n int) ParseOption
InitialCapacity is a option of perser to configure initial capacity of Forwarded slice.
Click to show internal directories.
Click to hide internal directories.