-
Notifications
You must be signed in to change notification settings - Fork 2
/
protocol.go
83 lines (65 loc) · 2.02 KB
/
protocol.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package serverconfigs
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ossconfigs"
type Protocol string
const (
ProtocolHTTP Protocol = "http"
ProtocolHTTPS Protocol = "https"
ProtocolTCP Protocol = "tcp"
ProtocolTLS Protocol = "tls"
ProtocolUDP Protocol = "udp"
// 子协议
ProtocolHTTP4 Protocol = "http4"
ProtocolHTTP6 Protocol = "http6"
ProtocolHTTPS4 Protocol = "https4"
ProtocolHTTPS6 Protocol = "https6"
ProtocolTCP4 Protocol = "tcp4"
ProtocolTCP6 Protocol = "tcp6"
ProtocolTLS4 Protocol = "tls4"
ProtocolTLS6 Protocol = "tls6"
)
func AllProtocols() []Protocol {
return []Protocol{ProtocolHTTP, ProtocolHTTPS, ProtocolTCP, ProtocolTLS, ProtocolUDP, ProtocolHTTP4, ProtocolHTTP6, ProtocolHTTPS4, ProtocolHTTPS6, ProtocolTCP4, ProtocolTCP6, ProtocolTLS4, ProtocolTLS6}
}
func (this Protocol) IsHTTPFamily() bool {
return this == ProtocolHTTP || this == ProtocolHTTP4 || this == ProtocolHTTP6
}
func (this Protocol) IsHTTPSFamily() bool {
return this == ProtocolHTTPS || this == ProtocolHTTPS4 || this == ProtocolHTTPS6
}
func (this Protocol) IsTCPFamily() bool {
return this == ProtocolTCP || this == ProtocolTCP4 || this == ProtocolTCP6
}
func (this Protocol) IsTLSFamily() bool {
return this == ProtocolTLS || this == ProtocolTLS4 || this == ProtocolTLS6
}
func (this Protocol) IsUDPFamily() bool {
return this == ProtocolUDP
}
func (this Protocol) IsOSS() bool {
return ossconfigs.IsOSSProtocol(this.String())
}
// Primary 主协议
func (this Protocol) Primary() Protocol {
switch this {
case ProtocolHTTP, ProtocolHTTP4, ProtocolHTTP6:
return ProtocolHTTP
case ProtocolHTTPS, ProtocolHTTPS4, ProtocolHTTPS6:
return ProtocolHTTPS
case ProtocolTCP, ProtocolTCP4, ProtocolTCP6:
return ProtocolTCP
case ProtocolTLS, ProtocolTLS4, ProtocolTLS6:
return ProtocolTLS
case ProtocolUDP:
return ProtocolUDP
default:
return this
}
}
// Scheme schema
func (this Protocol) Scheme() string {
return string(this)
}
// 转换为字符串
func (this Protocol) String() string {
return string(this)
}