mirror of
https://github.com/taigrr/systemctl.git
synced 2026-03-09 00:14:38 -07:00
* refactor: clean up unused code, fix typos, improve docs - Remove unused 'killed' const and 'unitTypes' var (staticcheck U1000) - Replace regexp with strings.TrimSuffix+switch in isFailed for consistency - Fix typo: 'programatically' -> 'programmatically' - Fix typo: 'an an int' -> 'as an int' in README and helpers.go - Add missing godoc comments on exported helper functions - Bump minimum Go version from 1.18 to 1.21 * refactor: use unused constants instead of removing them - Export unitTypes as UnitTypes and add HasValidUnitSuffix helper - Use killed const (exit code 130) in execute() to detect SIGINT - Update go.mod to go 1.26
43 lines
701 B
Go
43 lines
701 B
Go
package systemctl
|
|
|
|
import "strings"
|
|
|
|
type Options struct {
|
|
UserMode bool
|
|
}
|
|
|
|
type Unit struct {
|
|
Name string
|
|
Load string
|
|
Active string
|
|
Sub string
|
|
Description string
|
|
}
|
|
|
|
// UnitTypes contains all valid systemd unit type suffixes.
|
|
var UnitTypes = []string{
|
|
"automount",
|
|
"device",
|
|
"mount",
|
|
"path",
|
|
"scope",
|
|
"service",
|
|
"slice",
|
|
"snapshot",
|
|
"socket",
|
|
"swap",
|
|
"target",
|
|
"timer",
|
|
}
|
|
|
|
// HasValidUnitSuffix checks whether the given unit name ends with a valid
|
|
// systemd unit type suffix (e.g. ".service", ".timer").
|
|
func HasValidUnitSuffix(unit string) bool {
|
|
for _, t := range UnitTypes {
|
|
if strings.HasSuffix(unit, "."+t) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|