Golang native implementation Udev library
go get github.com/citilinkru/libudev
sc := libudev.NewScanner()
err, devices := s.ScanDevices()m := matcher.NewMatcher()
m.SetStrategy(matcher.StrategyOr)
m.AddRule(matcher.NewRuleAttr("dev", "189:133"))
m.AddRule(matcher.NewRuleEnv("DEVNAME", "usb/lp0"))
filteredDevices := m.Match(devices)if device.Parent != nil {
fmt.Printf("%s\n", device.Parent.Devpath)
}fmt.Printf("Count children devices %d\n", len(device.Children))- 100% Native code
- Without external dependencies
- Code is covered by tests
- Need at least
go1.13or newer.
You can read package documentation here or read tests.
Unit-tests:
go test -race -v ./...- Fork
- Write code
- Run unit test:
go test -v ./... - Run go vet:
go vet -v ./... - Run go fmt:
go fmt ./... - Commit changes
- Create pull-request