英文:
best way to handle different events in golang
问题
我想在Go语言中实现一种方法来响应三种不同类型的事件:
- 文本文件的更改(inotify)
- 定时事件(计时器已结束)
- 接收到Linux信号(SIGUSR1)
该软件应该无限期地等待空闲中的事件,如果接收到来自文件更改、定时器或信号的事件,则应调用相应的处理函数。
事件处理完成后,应继续等待事件。
我查看了通道,为每个事件使用单独的goroutine,但迄今为止没有找到符合我的要求的解决方案。
有人有建议或示例,可以告诉我如何以最佳方式在Go语言中实现这个功能吗?
非常感谢!
英文:
I want to implement in golang a method to react to three different kind of events:
- changes in a text file (inotify)
- Timerevents (timer has ended)
- Linux signal received (SIGUSR1)
The sw should wait infinitely for events in idle, and if events from filechanges, timers or signals get received, the according handling-functions should be called.
After the eventhandling the waiting for events should continue.
I had a look at channels, where for each of the events
a separate goroutine get used, but found nothing so far that would fit my demands..
Does anybody have a suggestion or example how this could be done in golang the best way?
Thanks a lot!
答案1
得分: 2
文件系统通知
https://github.com/fsnotify/fsnotify
定时器事件
https://gobyexample.com/timers
信号处理
https://gobyexample.com/signals
^ syscall
库支持 SIGUSR1 信号。
英文:
Filesystem Notifications
https://github.com/fsnotify/fsnotify
Timer Events
https://gobyexample.com/timers
Signal Handling
https://gobyexample.com/signals
^ the syscall
library supports SIGUSR1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论