Files
threshold/internal/target/subtype.go
T
Michael Gaffney 21033a6174 Refactor: multiple rename to fix the spelling of subtype (#1227)
The definition of 'subtype' is 'a secondary or subordinate type'. The
'T' should not be capitalized (unless it is referring to a type of
submarine, which its not).
2021-05-17 15:36:45 -04:00

42 lines
859 B
Go

package target
import (
"strings"
)
type Subtype int
const (
UnknownSubtype Subtype = iota
TcpSubtype
)
func (t Subtype) String() string {
switch t {
case TcpSubtype:
return "tcp"
}
return "unknown"
}
// SubtypeFromType converts a string to a Subtype.
// returns UnknownSubtype if no Subtype with that name is found.
func SubtypeFromType(t string) Subtype {
switch {
case strings.EqualFold(strings.TrimSpace(t), TcpSubtype.String()):
return TcpSubtype
}
return UnknownSubtype
}
// SubtypeFromId takes any public id in the target subsystem and uses the prefix to determine
// what subtype the id is for.
// Returns UnknownSubtype if no Subtype with this id's prefix is found.
func SubtypeFromId(id string) Subtype {
switch {
case strings.HasPrefix(strings.TrimSpace(id), TcpTargetPrefix):
return TcpSubtype
}
return UnknownSubtype
}