stail

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2021 License: MIT Imports: 8 Imported by: 0

README

中文 | English

🚀 介绍

Stail

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

🔧 安装

go get github.com/Licoy/stail

🔨 使用

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()
}

相当于

tail -{tailLine}f {filepath}

💡 参数

  • filepath 需要监听的文件路径
  • tailLine 只查看末尾的指定行
  • call 内容回调func,内容类型为string

📝 协议

MIT

Documentation

Index

Constants

View Source
const (
	OsWindows = "windows"
	OsLinux   = "linux"
	OsDarwin  = "darwin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	PowerShellPath string
	UnixTailPath   string
}

type STail

type STail interface {
	// Tail 在{filepath}文件中从末尾的{tailLine}行开始获取数据
	Tail(filepath string, tailLine int, call func(content string)) (item STailItem, err error)
	// TailTotal 在{filepath}文件从开头获取数据
	TailTotal(filepath string, call func(content string)) (item STailItem, err error)
}

func New

func New(opt Options) (res STail, err error)

type STailItem added in v0.0.3

type STailItem interface {
	Watch()
	Close() (err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL