初始版本.

Signed-off-by: chen.yang <chen.yang@yuzhen-iot.com>
This commit is contained in:
chen.yang 2022-01-17 17:23:02 +08:00
parent eeac7cd272
commit df0a9f758e
3 changed files with 40 additions and 0 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@
# Dependency directories (remove the comment below to include it)
# vendor/
go.sum

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module MUEvent
go 1.16
require github.com/deniswernert/udev v0.0.0-20170418162847-a12666f7b5a1

34
main.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"log"
"time"
"github.com/deniswernert/udev"
)
var UNotify chan *udev.UEvent
func Mon() {
for {
uevent := <-UNotify
log.Println("UEvent.Action: ", uevent.Action)
log.Println("UEvent.Devpath: ", uevent.Devpath)
log.Println("UEvent.Env: ", uevent.Env)
log.Println()
}
}
func main() {
UNotify = make(chan *udev.UEvent, 128)
mon, e := udev.NewMonitor()
if e != nil {
panic(e)
}
go Mon()
mon.Monitor(UNotify)
for {
time.Sleep(1 * time.Second)
}
}