49 lines
812 B
Go
49 lines
812 B
Go
package protocol
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Protocols supported by this package.
|
|
const (
|
|
ProtocolDNS = "dns"
|
|
ProtocolHTTP = "http"
|
|
ProtocolMQTT = "mqtt"
|
|
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
|
|
}
|