Retrieving file timestamps in Go

Recently, a friend of mine needed to get the creation time of a file in a Go project. There’s os.Stat , so how hard can it be, right? os.Stat returns fs.FileInfo which is an interface with six methods: type FileInfo interface { Name() string // base name of the file Size() int64 // length in bytes for regular files; [..] Mode() FileMode // file mode bits ModTime() time.Time // modification time IsDir() bool // abbreviation for Mode().IsDir() Sys() any // underlying data source (can return nil) } Time of last modification (mtime) is the only time reported by this interface, though. There is no time of last access (atime), creation (btime), nor status change (ctime). ...

19 May 2024 · 906 words