import ( "github.com/syncthing/syncthing/lib/protocol" "os" ) func main() { fi, err := os.Stat("example.txt") if err != nil { panic(err) } fileInfo := protocol.FileInfo{ Name: fi.Name(), Size: uint64(fi.Size()), Mode: fi.Mode().Perm(), ModTime: fi.ModTime().Unix(), } // use fileInfo object for further operations }
import ( "encoding/json" "github.com/syncthing/syncthing/lib/protocol" ) func main() { fileInfo := protocol.FileInfo{ Name: "example.txt", Size: 1024, Mode: 0777, ModTime: 1606347300, } // convert to JSON jsonBytes, err := json.Marshal(fileInfo) if err != nil { panic(err) } // use jsonBytes for further operations }Overall, the FileInfo struct is a useful and versatile tool for working with file metadata in Go programs, especially in the context of file synchronization and sharing.