当前位置:网站首页>go --- 监控文件变化
go --- 监控文件变化
2022-06-12 20:18:00 【谬也】
在对文件进行热更新时,需要监听文件的变化,记录下go中实现文件监听的一种方式。
go代码示例:
当文件被重命名或删除时,执行更新操作(此处为打印delete)
package main
import (
"fmt"
"github.com/fsnotify/fsnotify"
)
func main(){
watcher, _ := fsnotify.NewWatcher()
watcher.Add("test.txt")
defer watcher.Close();
select {
case event := <-watcher.Events:
{
if event.Op&fsnotify.Rename == fsnotify.Rename || event.Op&fsnotify.Remove == fsnotify.Remove {
fmt.Println("delete")
} else if event.Op&fsnotify.Write == fsnotify.Write {
} else if event.Op&fsnotify.Create == fsnotify.Create {
}
}
case err := <-watcher.Errors:
fmt.Println(err.Error())
}
}
如有不对,烦请指出,感谢~
边栏推荐
- Using / developing private plug-ins in traifik proxy 2.5 (traifik official blog)
- Scalars, vectors, arrays, and matrices
- Wechat jsapi payment pit summary
- Centos7 installing PHP
- 20 shortcut keys for vs code!
- Demand and business model innovation-5-process
- Handwritten promise
- Is online futures account reliable? Is it safe to open an online futures account?
- Understand Jack Dorsey's web5 from the ppt on page 16
- [leetcode] small thinking of optimal division
猜你喜欢

牛客网:三数之和

EditText控制从左上角开始

How to determine fragment restored from Backstack

Process accounting, process time, daemon

system()

Macro definitions and functions

BigTable (II): how BigTable achieves scalability and high performance

Demand and business model innovation - demand 2- demand basis

The joint empowerment plan of Baidu PaddlePaddle large enterprise open innovation center was launched! Help Pudong to upgrade its industry intelligently

2022年最新宁夏建筑安全员模拟题库及答案
随机推荐
system()
torch 网络模型转换onnx格式,并可视化
新来的同事问我 where 1=1 是什么意思???
centos7 安装 mysql 5.7
牛客网:三数之和
QT pro文件配置ffmpeg宏
Kyma application connectivity feature introduction
P5076 [Fondation profonde 16. Exemple 7] Arbre binaire commun (version simplifiée)
系统 日志
Demand and business model innovation-5-process
Viewpoint sharing | Li Wei, an expert of Gewu titanium intelligent technology products: underlying logic and scenario practice of unstructured data platform
When will the index fail
MySQL日志
What does MySQL full value match mean
【GAMES101】课堂笔记8–着色(着色频率、图形管线、纹理映射)
登录mysql
sklearn中随机森林RandomForestClassifier的参数含义
登錄mysql
MySQL - the execution order of an SQL statement
Demand and business model analysis-3-design