Files
dpi/protocol/protocol.go
2025-10-08 20:53:56 +02:00

48 lines
783 B
Go

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
}