{"id":13601069,"url":"https://github.com/dengsgo/fileboy","last_synced_at":"2026-01-03T06:04:43.765Z","repository":{"id":46594479,"uuid":"148241967","full_name":"dengsgo/fileboy","owner":"dengsgo","description":"fileboy，文件变更监听通知工具，使用 Go 编写。Fileboy, File Change Monitoring Notification Tool, written with Go.","archived":false,"fork":false,"pushed_at":"2024-06-01T10:18:02.000Z","size":300,"stargazers_count":496,"open_issues_count":2,"forks_count":69,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-11-07T03:42:44.943Z","etag":null,"topics":["file","fsnotify","go","gowatch","monitor","monitoring","notification","notify","tool","watch"],"latest_commit_sha":null,"homepage":"https://www.yoytang.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dengsgo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-11T01:24:49.000Z","updated_at":"2024-09-29T05:38:09.000Z","dependencies_parsed_at":"2024-06-18T20:07:05.739Z","dependency_job_id":"42a10031-9a51-49bf-8078-13c5dea6060f","html_url":"https://github.com/dengsgo/fileboy","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengsgo%2Ffileboy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengsgo%2Ffileboy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengsgo%2Ffileboy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengsgo%2Ffileboy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dengsgo","download_url":"https://codeload.github.com/dengsgo/fileboy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248325016,"owners_count":21084851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file","fsnotify","go","gowatch","monitor","monitoring","notification","notify","tool","watch"],"created_at":"2024-08-01T18:00:54.699Z","updated_at":"2026-01-03T06:04:43.683Z","avatar_url":"https://github.com/dengsgo.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## 项目说明  \n\n![Go](https://github.com/dengsgo/fileboy/workflows/Go/badge.svg?branch=master) [![Build Status](https://travis-ci.org/dengsgo/fileboy.svg?branch=master)](https://travis-ci.org/dengsgo/fileboy) [![Go Report Card](https://goreportcard.com/badge/github.com/dengsgo/fileboy)](https://goreportcard.com/report/github.com/dengsgo/fileboy)\n\n[简体中文](README.md) | [ENGLISH](README_EN.md)\n\nfileboy，文件变更监听通知工具，使用 Go 编写。  \n适用于 Hot Reload （典型的如开发go项目，无需每次手动执行 go build；又比如前端 node 打包） 或者 系统监控的场景。  \n\n## 特性  \n\n- 极简的用法和配置  \n- 支持多平台，Windows/Linux/MacOS  \n- 支持自定义文件监听范围，监听指定文件夹/不监听指定文件夹/指定后缀文件  \n- 支持自定义监控事件（write/rename/remove/create/chmod）  \n- 支持设置多条命令  \n- 命令支持变量占位符  \n- 支持冗余任务丢弃，自定义冗余任务范围  \n- 支持 http 通知  \n- 高级指令用法  \n- 更多...  \n\n## 编译环境    \n\nGo \u003e= 1.17   \n\n## 更新日志  \n\n[CHANGELOG](CHANGELOG.md)  \n\n## 运行    \n\n### 下载二进制文件   \n\nGithub: [download v1.17](https://github.com/dengsgo/fileboy/releases)  \nGitee:  [dowmload v1.17](https://gitee.com/dengsgo/fileboy/releases)  \n\n下载已经编译好的对应平台二进制文件，重命名为`fileboy`, 加入系统 Path 中即可。 \n\n### 源码编译   \n\nclone 该项目，进入主目录，运行命令:  \n```bash\n## 确保本地 Go 启用 modules  \nexport GO111MODULE=on  \ngo env -w GOPROXY=https://goproxy.io,direct\n## 安装依赖\ngo get -u \n## 编译\ngo build\n## 运行\n./fileboy\n```\n\n## 使用\n\nfileboy 的正常运行依赖于 `filegirl.yaml` 配置文件，因此首次在项目中使用需要初始化 `filegirl.yaml`。  \n- 进入你想要 hot reload 的项目主目录下；  \n- 运行 `fileboy init`，会在该目录下生成 `filegirl.yaml`文件；  \n- 查看 `filegirl.yaml`,修改为适合自己项目的配置项；  \n- 运行 `fileboy`即可.  \n  \n如果你定义了 `command -\u003e exec`命令，想事先确认是否能正常执行，可以运行 `fileboy exec`命令，系统会尝试运行你的自定义命令。  \n你可以使用 `fileboy help`查看使用帮助。   \n\n## filegirl.yaml 配置文件说明\n\n```yaml\n####################\n## 运行 fileboy 所在的路径为工作目录;\n## 使用 -filegirl 命令参数可以加载指定路径的 filegirl 配置（不限定工作目录），如 \"fileboy -filegirl /user/f/go.yml\" 或者 \"fileboy -filegirl ../../f/go.yml\";\n####################\n\n# 主配置\ncore:\n    # 配置版本号\n    version: 1\n\n# 监控配置\nmonitor:\n    # 要监听的目录。必须是工作目录下的路径\n    # test1       监听当前目录下 test1 目录\n    # test1/test2 监听当前目录下 test1/test2 目录\n    # test1,*     监听当前目录下 test1 目录及其所有子目录（递归）\n    # .,*         监听当前目录及其所有子目录（递归）\n    includeDirs:\n        - .,*\n\n    # 不监听的目录。必须是工作目录下的路径\n    # .idea   忽略.idea目录及其所有子目录的监听\n    exceptDirs:\n        - .idea\n        - .git\n        - .vscode\n        - node_modules\n        - vendor\n\n    # 监听文件的格式，此类文件更改会执行 command 中的命令\n    # .go   后缀为 .go 的文件更改，会执行 command 中的命令\n    # .*    所有的文件更改都会执行 command 中的命令\n    types:\n        - .go\n\n    # 监听的事件类型，发生此类事件才执行 command 中的命令\n    # 没有该配置默认监听所有事件\n    # write   写入文件事件\n    # rename  重命名文件事件\n    # remove  移除文件事件\n    # create  创建文件事件\n    # chmod   更新文件权限事件(类unix)\n    events:\n        - write\n        - rename\n        - remove\n        - create\n        - chmod\n\n# 命令\ncommand:\n    # 监听的文件有更改会执行的命令\n    # 可以有多条命令，会依次执行\n    # 如有多条命令，每条命令都会等待上一条命令执行完毕后才会执行\n    # 如遇交互式命令，允许外部获取输入\n    # 支持变量占位符,运行命令时会替换成实际值：\n    #    {{file}}    文件名(如 a.txt 、test/test2/a.go)\n    #    {{ext}}     文件后缀(如 .go)\n    #    {{event}}   事件(上面的events, 如 write)\n    #    {{changed}} 文件更新的本地时间戳(纳秒,如 1537326690523046400)\n    # 变量占位符使用示例：cp {{file}} /root/sync -rf  、 myCommand --{{ext}} {{changed}}\n    exec:\n        - go version\n        - go env\n\n    # 文件变更后命令在xx毫秒后才会执行，单位为毫秒\n    # 一个变更事件(A)如果在定义的延迟时间(t)内, 又有新的文件变更事件(B), 那么A会取消执行。\n    # B及以后的事件均依次类推，直到事件Z在t内没有新事件产生，Z 会执行\n    # 合理设置延迟时间，将有效减少冗余和重复任务的执行\n    # 如果不需要该特性，设置为 0\n    delayMillSecond: 2000\n\n# 通知器\nnotifier:\n    # 文件更改会向该 url 发送请求（POST 一段 json 文本数据）\n    # 触发请求的时机和执行 command 命令是一致的\n    # 请求超时 15 秒\n    # POST 格式:\n    #    Content-Type: application/json;charset=UTF-8\n    #    User-Agent: FileBoy Net Notifier v1.17\n    #    Body: {\"project_folder\":\"/project/path\",\"file\":\"main.go\",\"changed\":1576567861913824940,\"ext\":\".go\",\"event\":\"write\"}\n    # 例: http://example.com/notifier/fileboy-listener\n    # 不启用通知，请留空 \"\"\n    callUrl: \"\"\n\n# 特殊指令\ninstruction:\n    # 可以通过特殊的指令选项来控制 command 的行为，指令可以有多个\n    # 指令选项解释：\n    #   exec-when-start    fileboy启动就绪后，自动执行一次 'exec' 定义的命令\n    #   should-finish      触发执行 'exec' 时(C)，如果上一次的命令(L)未退出（还在执行），会等待 L 退出（而不是强制 kill ），直到 L 有明确 exit code 才会开始执行本次命令。\n    #                      在等待 L 退出时，又有新事件触发了命令执行(N)，则 C 执行取消，只会保留最后一次的 N 执行\n    #   ignore-stdout      执行 'exec' 产生的 stdout 会被丢弃\n    #   ignore-warn        fileboy 自身的 warn 信息会被丢弃\n    #   ignore-info        fileboy 自身的 info 信息会被丢弃\n    #   ignore-exec-error  执行 'exec' 出错仍继续执行下面的命令而不退出 \n\n    #- should-finish\n    #- exec-when-start\n    - ignore-warn\n```\n\n## QA\n\n### 很多框架都自带了 hot reload 的功能，为什么还要单独写个 fileboy 呢？  \n\n这个是一款通用的 hot reload 的软件，理论上适用于任何需要 hot reload 的场景，并不局限于语言层面上。只要灵活的配置 `filegirl.yaml`文件就行了。  \n\n### fileboy 可以应用在那些具体的场景？  \n\n在开发中，我们很需要一款可以帮助我们自动打包编译的工具，那 fileboy 就非常适合这样的场景。比如 go 项目的热编译，让我们可以边修改代码边运行得到反馈。又比如 PHP Swoole 框架，由于常驻进程的原因，无法更改代码立即reload，使用 fileboy 就可以辅助做到传统 PHP 开发的体验。  \n对于一些需要监控文件日志或者配置变动的场景， fileboy 同样适合。你可以事先编写好相应的通知报警脚本，然后定义`filegirl.yaml`中的`command`命令，交由 fileboy 自动运行监控报警。  \n\n### 通知器在什么时候会发送 http 请求 ?\n\n通知器发送 http 通知的前提是在配置文件中设置了 `callUrl` 参数（不为空即为已设置）。触发请求的时机和执行 command 命令是一致的，`command -\u003e delayMillSecond` 参数对于触发器同样有效。请求超时默认15秒.  \n\n### idea 下更改文件，为什么会执行两次或者多次 command ?\n\n由于 idea 系列软件特殊的文件保存策略，他会自动创建一些临时文件，并且在需要时多次重写文件，所以有时反映在文件上就是有多次的更改，所以会出现这种情况。1.5之后的版本增加了 `delayMillSecond` 参数，可以解决这个问题。  \n\n### filegirl.yaml 里面的 command 如何配置复杂命令？  \n\nfileboy 目前支持 `命令 + 参数`这种形式的 command，而且 参数中不能有\"\"符号或者有空格。如：  \n`go build`:支持；  \n`go env`:支持;  \n`php swoole start --daemon`:支持  \n`cat a.txt | grep \"q\" | wc -l`:不支持  \n对于不支持的命令，可以把它写到一个文件里，然后在 command 中执行这个文件来解决。  \n\n### 为什么起名为 fileboy，又把配置名叫做 filegirl ？\n\n因为爱情~~ (◡ᴗ◡✿)  \n\n\n\n## 贡献者\n\n|   |   |   |\n| ------------ | ------------ | ------------ |\n| \u003ca href=\"https://github.com/dengsgo\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/7929002?s=460\u0026v=4\" width=64 style=\"border-radius:45px;\" /\u003e\u003c/a\u003e | \u003ca href=\"https://github.com/jason-gao\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/9896574?s=460\u0026v=4\" width=64 style=\"border-radius:45px;\" /\u003e\u003c/a\u003e | \u003ca href=\"https://github.com/itwesley\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/1928721?s=460\u0026v=4\" width=64 style=\"border-radius:45px;\" /\u003e\u003c/a\u003e |\n\n## 感谢支持  \n\n|   |\n| ------------ |\n| \u003ca href=\"https://www.jetbrains.com/?from=fileboy\"\u003e\u003cimg src=\"./resources/jetbrains.png\" width=140 /\u003e\u003c/a\u003e |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdengsgo%2Ffileboy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdengsgo%2Ffileboy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdengsgo%2Ffileboy/lists"}