source: code/trunk/vendor/github.com/pires/go-proxyproto/version_cmd.go@ 824

Last change on this file since 824 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 1.5 KB
Line 
1package proxyproto
2
3// ProtocolVersionAndCommand represents the command in proxy protocol v2.
4// Command doesn't exist in v1 but it should be set since other parts of
5// this library may rely on it for determining connection details.
6type ProtocolVersionAndCommand byte
7
8const (
9 // LOCAL represents the LOCAL command in v2 or UNKNOWN transport in v1,
10 // in which case no address information is expected.
11 LOCAL ProtocolVersionAndCommand = '\x20'
12 // PROXY represents the PROXY command in v2 or transport is not UNKNOWN in v1,
13 // in which case valid local/remote address and port information is expected.
14 PROXY ProtocolVersionAndCommand = '\x21'
15)
16
17var supportedCommand = map[ProtocolVersionAndCommand]bool{
18 LOCAL: true,
19 PROXY: true,
20}
21
22// IsLocal returns true if the command in v2 is LOCAL or the transport in v1 is UNKNOWN,
23// i.e. when no address information is expected, false otherwise.
24func (pvc ProtocolVersionAndCommand) IsLocal() bool {
25 return LOCAL == pvc
26}
27
28// IsProxy returns true if the command in v2 is PROXY or the transport in v1 is not UNKNOWN,
29// i.e. when valid local/remote address and port information is expected, false otherwise.
30func (pvc ProtocolVersionAndCommand) IsProxy() bool {
31 return PROXY == pvc
32}
33
34// IsUnspec returns true if the command is unspecified, false otherwise.
35func (pvc ProtocolVersionAndCommand) IsUnspec() bool {
36 return !(pvc.IsLocal() || pvc.IsProxy())
37}
38
39func (pvc ProtocolVersionAndCommand) toByte() byte {
40 if pvc.IsLocal() {
41 return byte(LOCAL)
42 } else if pvc.IsProxy() {
43 return byte(PROXY)
44 }
45
46 return byte(LOCAL)
47}
Note: See TracBrowser for help on using the repository browser.