Libudev
Golang native implementation udev library
Install / Use
/learn @citilinkru/LibudevREADME
libudev
Golang native implementation Udev library
Installation
go get github.com/citilinkru/libudev
Usage
Scanning devices
sc := libudev.NewScanner()
err, devices := s.ScanDevices()
Filtering devices
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)
Getting parent device
if device.Parent != nil {
fmt.Printf("%s\n", device.Parent.Devpath)
}
Getting children devices
fmt.Printf("Count children devices %d\n", len(device.Children))
Features
- 100% Native code
- Without external dependencies
- Code is covered by tests
Requirements
- Need at least
go1.13or newer.
Documentation
You can read package documentation here or read tests.
Testing
Unit-tests:
go test -race -v ./...
Contributing
- 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
