go-file
Package file is a Go library to open files with file locking depending on the system.
Install
go get github.com/mithrandie/go-file
Supported Systems
Currently file locking on the following systems are supported.
darwin dragonfly freebsd linux netbsd openbsd solaris
Advisory Lock
windows
Mandatory Lock
android nacl plan9 zos
Not Supported
Example
package main
import (
"bufio"
"fmt"
"github.com/mithrandie/go-file"
)
func main() {
fp, err := file.OpenToRead("/path/to/file")
if err != nil {
panic(err)
}
defer file.Close(fp)
scanner := bufio.NewScanner(fp)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}