mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-01-05 03:05:48 +08:00
阶段性提交
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package serverconfigs
|
||||
|
||||
type Protocol = string
|
||||
type Protocol string
|
||||
|
||||
const (
|
||||
ProtocolHTTP Protocol = "http"
|
||||
@@ -27,3 +27,52 @@ const (
|
||||
func AllProtocols() []Protocol {
|
||||
return []Protocol{ProtocolHTTP, ProtocolHTTPS, ProtocolTCP, ProtocolTLS, ProtocolUnix, 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) IsUnixFamily() bool {
|
||||
return this == ProtocolUnix
|
||||
}
|
||||
|
||||
func (this Protocol) IsUDPFamily() bool {
|
||||
return this == ProtocolUDP
|
||||
}
|
||||
|
||||
// 主协议
|
||||
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 ProtocolUnix:
|
||||
return ProtocolUnix
|
||||
case ProtocolUDP:
|
||||
return ProtocolUDP
|
||||
default:
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为字符串
|
||||
func (this Protocol) String() string {
|
||||
return string(this)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user