Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/licoy/stail

:rocket: 通过系统级的命令(如`tail -f`)来循环显示文件尾部数据 | Use system-level commands (such as `tail -f`) to display tail data in a loop
https://github.com/licoy/stail

fsnotify monitor powershell tail

Last synced: 19 days ago
JSON representation

:rocket: 通过系统级的命令(如`tail -f`)来循环显示文件尾部数据 | Use system-level commands (such as `tail -f`) to display tail data in a loop

Awesome Lists containing this project

README

        

中文 | [English](./README_EN.md)

## :rocket: 介绍


Stail


通过系统级的命令( 如 `tail -f` )来实时监控文件变动


## :wrench: 安装
```
go get github.com/Licoy/stail
```
## :hammer: 使用
```golang
func useSTail(filepath string, tailLine int) {
st, err := stail.New(stail.Options{})
if err != nil {
fmt.Println(err)
return
}
si, err := st.Tail(filepath, tailLine, func(content string) {
fmt.Print(fmt.Sprintf("获取到内容: %s", content))
})
if err != nil {
fmt.Println(err)
return
}
time.AfterFunc(time.Second*10, func() {
err = si.Close() // 10s之后关闭获取通道
}
si.Watch()
}
```
相当于
```bash
tail -{tailLine}f {filepath}
```
## :bulb: 参数
- `filepath` 需要监听的文件路径
- `tailLine` 只查看末尾的指定行
- `call` 内容回调func,内容类型为string

## :memo: 协议
[MIT](./LICENSE)