// Copyright 2023 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package fsimport ()// FormatFileInfo returns a formatted version of info for human readability.// Implementations of FileInfo can call this from a String method.// The output for a file named "hello.go", 100 bytes, mode 0o644, created// January 1, 1970 at noon is//// -rw-r--r-- 100 1970-01-01 12:00:00 hello.gofunc ( FileInfo) string { := .Name() := make([]byte, 0, 40+len()) = append(, .Mode().String()...) = append(, ' ') := .Size()varuint64if >= 0 { = uint64() } else { = append(, '-') = uint64(-) }var [20]byte := len() - 1for >= 10 { := / 10 [] = byte('0' + - *10) -- = } [] = byte('0' + ) = append(, [:]...) = append(, ' ') = append(, .ModTime().Format(time.DateTime)...) = append(, ' ') = append(, ...)if .IsDir() { = append(, '/') }returnstring()}// FormatDirEntry returns a formatted version of dir for human readability.// Implementations of DirEntry can call this from a String method.// The outputs for a directory named subdir and a file named hello.go are://// d subdir/// - hello.gofunc ( DirEntry) string { := .Name() := make([]byte, 0, 5+len())// The Type method does not return any permission bits, // so strip them from the string. := .Type().String() = [:len()-9] = append(, ...) = append(, ' ') = append(, ...)if .IsDir() { = append(, '/') }returnstring()}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.