Initial import
This commit is contained in:
47
protocol/protocol.go
Normal file
47
protocol/protocol.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Protocols supported by this package.
|
||||
const (
|
||||
ProtocolDNS = "dns"
|
||||
ProtocolHTTP = "http"
|
||||
ProtocolMySQL = "mysql"
|
||||
ProtocolPostgreSQL = "postgresql"
|
||||
ProtocolSSH = "ssh"
|
||||
ProtocolSSL = "ssl"
|
||||
ProtocolTLS = "tls"
|
||||
)
|
||||
|
||||
type Protocol struct {
|
||||
Name string
|
||||
Version Version
|
||||
}
|
||||
|
||||
type Version struct {
|
||||
Major int
|
||||
Minor int
|
||||
Patch int
|
||||
Extra string
|
||||
}
|
||||
|
||||
func (v Version) String() string {
|
||||
p := make([]string, 0, 3)
|
||||
if v.Major >= 0 {
|
||||
p = append(p, strconv.Itoa(v.Major))
|
||||
if v.Minor >= 0 {
|
||||
p = append(p, strconv.Itoa(v.Minor))
|
||||
if v.Patch >= 0 {
|
||||
p = append(p, strconv.Itoa(v.Patch))
|
||||
}
|
||||
}
|
||||
}
|
||||
s := strings.Join(p, ".")
|
||||
if v.Extra != "" {
|
||||
return s + "-" + v.Extra
|
||||
}
|
||||
return s
|
||||
}
|
Reference in New Issue
Block a user