The following example will print out all the metadata available about a file. It includes the obvious attributes, namely name, size, permissions, last modified time, and whether it is a directory. The last data piece it contains is the FileInfo.Sys() interface. This contains information about the underlying source of the file, which is most commonly a filesystem on a hard disk:
package main import ( "fmt" "log" "os" ) func main() { // Stat returns file info. It will return // an error if there is no file. fileInfo, err := os.Stat("test.txt") if err != nil { log.Fatal(err) } fmt.Println("File name:", fileInfo.Name()) fmt.Println("Size in bytes:", fileInfo.Size()) fmt.Println("Permissions:", fileInfo.Mode()) fmt.Println("Last ...