Skip to content

masa23/gotail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gotail GoDoc MIT licensed

gotail is Go library for reading data from realtime updating file , read like "tail -f" command.
See https://godoc.org/github.com/masa23/gotail for the API document.

License

MIT

Example

// init construct
const (
	LogFile = "./test.log"
	PosFile = "./test.log.pos"
)

func main() {
	go func() {
		fd, err := os.OpenFile(LogFile, os.O_WRONLY|os.O_CREATE, 0644)
		if err != nil {
			panic(err)
		}
		defer fd.Close()
		fd.Truncate(0)
		fd.Seek(0, 0)

		for {
			t := time.Now().String()
			fd.WriteString(t + "\n")
			fd.Sync()
			time.Sleep(time.Second)
		}
	}()
	tail, err := gotail.Open(LogFile, PosFile)
	if err != nil {
		panic(err)
	}


	for tail.Scan() {
		b := tail.Text()
		fmt.Println(b)
	}

	if err = tail.Err(); err != nil {
		panic(err)
	}
}