-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
43 lines (35 loc) · 1.41 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package proxyprotocol
import "net"
// HeaderParserBuilderFunc wrap builder func into HeaderParserBuilder
type HeaderParserBuilderFunc func(logger Logger) HeaderParser
// Build implement HeaderParserBuilder for build func
func (funcBuilder HeaderParserBuilderFunc) Build(logger Logger) HeaderParser {
return funcBuilder(logger)
}
// TextHeaderParserBuilder build TextHeaderParser
var TextHeaderParserBuilder = HeaderParserBuilderFunc(func(logger Logger) HeaderParser {
return NewTextHeaderParser(logger)
})
// BinaryHeaderParserBuilder build BinaryHeaderParser
var BinaryHeaderParserBuilder = HeaderParserBuilderFunc(func(logger Logger) HeaderParser {
return NewBinaryHeaderParser(logger)
})
// StubHeaderParserBuilder build StubHeaderParser
var StubHeaderParserBuilder = HeaderParserBuilderFunc(func(logger Logger) HeaderParser {
return NewStubHeaderParser()
})
// DefaultFallbackHeaderParserBuilder build FallbackHeaderParserBuilder with
// default HeaderParserList (TextHeaderParser, BinaryHeaderParser, StubHeaderParser)
var DefaultFallbackHeaderParserBuilder = NewFallbackHeaderParserBuilder(
TextHeaderParserBuilder,
BinaryHeaderParserBuilder,
StubHeaderParserBuilder,
)
// NewDefaultListener construct proxyprotocol.Listener from other net.Listener
// with DefaultFallbackHeaderParserBuilder.
func NewDefaultListener(listener net.Listener) Listener {
return NewListener(
listener,
DefaultFallbackHeaderParserBuilder,
)
}