https://github.com/arp242/follow
Go library to follow a file for changes; e.g. "tail -F".
https://github.com/arp242/follow
go
Last synced: 4 months ago
JSON representation
Go library to follow a file for changes; e.g. "tail -F".
- Host: GitHub
- URL: https://github.com/arp242/follow
- Owner: arp242
- License: other
- Created: 2020-07-26T14:16:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T23:26:19.000Z (about 2 years ago)
- Last Synced: 2025-03-16T09:51:36.605Z (over 1 year ago)
- Topics: go
- Language: Go
- Homepage:
- Size: 1.24 MB
- Stars: 20
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Go library to follow a file for changes; e.g. "tail -F".
There's a little example application in [`tail/main.go`](/tail/main.go):
```go
func main() {
if len(os.Args) <= 1 {
fmt.Println("need at least one filename")
os.Exit(1)
}
f := follow.New()
// Maximum time to retry opening the file after it goes away; -1 to keep
// trying forever.
f.Retry = -1
// Install signal handler; any signal sent to this will reopen the file; you
// can send something manually with:
// f.Reopen <- os.Interrupt
signal.Notify(f.Reopen, syscall.SIGHUP)
// Keep reading data in the background, sending it to the f.Data channel.
go func() { log.Fatal(f.Start(context.Background(), os.Args[1])) }()
for {
data := <-f.Data
if data.Err != nil {
if data.Err == io.EOF {
break
}
log.Fatal(data.Err)
}
fmt.Println("X", data)
}
}
```