-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: standard implementations of FileInfo and DirEntry should implement fmt.Stringer #54451
Comments
SGTM but please also propose just what it should print. |
The output would look a bit like ls -l: |
This proposal has been added to the active column of the proposals project |
If all our FileInfo and DirEntry implementations are going to add a String method, we should also provide helpers that all those implementations can call. Those would probably be:
and then implementations such as os.fileStat would do
It looks like these are the types affected by this proposal, which would all add String methods:
|
To summarize, the proposal is: (1) Add
to io/fs for use by any implementations that want them. (2) For all implementations in the standard library, define String methods calling those helpers. Do I have that right? Have all concerns about this been addressed? Updated 2023-04-12: changed names to FormatFileInfo and FormatDirEntry (formerly FileInfoString and DirEntryString). |
SGTM. To bikeshed, maybe call it |
Sure. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/489555 mentions this issue: |
Change https://go.dev/cl/491175 mentions this issue: |
For #54451 Change-Id: I3214066f77b1398ac1f2786ea035c83f32f0a826 Reviewed-on: https://go-review.googlesource.com/c/go/+/489555 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Joseph Tsai <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
Change https://go.dev/cl/499177 mentions this issue: |
Also document the new String methods that call them. For #54451 Change-Id: I5cd7e0fc6c84097bba6d29c4d6012ed3c8bb1e0d Reviewed-on: https://go-review.googlesource.com/c/go/+/499177 Reviewed-by: Eli Bendersky <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Bypass: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
2023-04-12: The current proposal is #54451 (comment).
For debugging purposes, one may want to print a
FileInfo
to see high-level information about the file without manually formatting each field in the interface (e.g., name, mode, modification date, size, etc.).For entries returned by
os
, the native representation is nicely printed byfmt
:go/src/os/file_unix.go
Lines 394 to 399 in 03fb5d7
However, the
embed.file
type has the following structure:go/src/embed/embed.go
Lines 218 to 224 in 03fb5d7
where printing a
embed.file
results in a potentially massive output being printed due to the entire file being contained inembed.file.data
.I propose we have all standard implementations (or just those that print poorly) of
fs.FileInfo
andfs.DirEntry
to implement aString
method that prints useful information.One possible default formatting is something similar to what the Unix
ls
command prints:The text was updated successfully, but these errors were encountered: