README.md (1244B)
1 [](https://pkg.go.dev/github.com/rubiojr/go-usbmon) 2 3 # USBMon 4 5 A lightweight Go wrapper around libudev to simplify monitoring USB device add/remove events. This package abstracts away the complexities of the low-level udev API, providing a simple interface for detecting and responding to USB devices being connected or disconnected. 6 7 ```Go 8 // monitor USB hotplug events 9 package main 10 11 import ( 12 "context" 13 "fmt" 14 15 "github.com/rubiojr/go-usbmon" 16 ) 17 18 func main() { 19 // Print device properties when plugged in or unplugged 20 filter := &usbmon.ActionFilter{Action: usbmon.ActionAll} 21 devs, err := usbmon.ListenFiltered(context.Background(), filter) 22 if err != nil { 23 panic(err) 24 } 25 26 for dev := range devs { 27 fmt.Printf("-- Device %s\n", dev.Action()) 28 fmt.Println("Serial: " + dev.Serial()) 29 fmt.Println("Path: " + dev.Path()) 30 fmt.Println("Vendor: " + dev.Vendor()) 31 } 32 } 33 ``` 34 35 ## Building 36 37 ### Requirements 38 39 * libudev 40 41 Ubuntu/Debian: `apt install libudev-dev` 42 43 Fedora/RHEL: `dnf install systemd-devel` 44 45 Arch Linux: `pacman -S systemd-libs` 46 47 ## Additional examples 48 49 See [examples](_examples) for more usage examples. 50 51 ## License 52 53 MIT - See [LICENSE](LICENSE) for details.