Skip to content

Instantly share code, notes, and snippets.

@brian-brazil
Created January 28, 2015 00:40
Show Gist options
  • Save brian-brazil/0022440426ea12728651 to your computer and use it in GitHub Desktop.
Save brian-brazil/0022440426ea12728651 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"os"
)
var path = flag.String("path", "./abc", "Path to create test file")
func main() {
flag.Parse()
f, err := os.Create(*path)
if err != nil {
panic(err)
}
f.Write([]byte("a\n"))
f.Close()
f, err = os.OpenFile(*path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
if err != nil {
panic(err)
}
f.Write([]byte("bc\n"))
offset, err := f.Seek(0, os.SEEK_CUR)
if err != nil {
panic(err)
}
fmt.Printf("lseek returns: %d Expected: 5\n", offset)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment