loading libudev.so with dynamic loading at runtime by libffigo
get this module
go get github.com/gogogoghost/libudevgo
init and create context
udev.init()
ctx, err := udev.NewContext()
if err != nil {
panic(err)
}
enumerate device
enumerator, err := udev.NewEnumerator(ctx)
if err != nil {
panic(err)
}
for _, dev := range enumerator.List() {
//read device
}
monitor event
monitor, err := udev.NewMonitor(ctx, udev.UDEV)
if err != nil {
panic(err)
}
monitor.AddFilter("tty", "")
channel, err := monitor.StartMonitor()
if err != nil {
panic(err)
}
for {
evt := <-channel
//read event and device
}