-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
mfs: add Inode
interface
#5182
mfs: add Inode
interface
#5182
Conversation
mfs/inode.go
Outdated
} | ||
|
||
// GetName returns the `Inode`'s name. | ||
func (i *Inode) GetName() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not access these directly? Would be cleaner imo (and look less than java)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not access these directly?
To make it explicit that it is a read-only attribute and should not be modified.
(and look less than java)
Would you prefer just using Name()
?
This is actually not happening right now in this PR, |
As mentioned in the Stack Overflow answer, the customary Go solution seems to be to define an interface ( |
Abstract common characteristics of the MFS `File` and `Directory` structures inside a separate interface called `Ìnode`. License: MIT Signed-off-by: Lucas Molas <[email protected]>
} | ||
|
||
// inode implements the `Inode` interface. | ||
type inode struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the appropriate name for the structure that implements the Inode
interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, thats what I would do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is just shared data (no logic), I'd just use a struct (and embed it in each file type). That would deduplicate the fields without adding additional complexity/overhead.
Pretty clean refactor, stevens right though, it probably makes sense to just embed a struct here. (unless you want to be able to mock out the inode stuff for some reason in testing) |
Not really, my main motivation for the interface was to be able to enforce read-only attributes (more as a code clarification feature than to protect inadvertent modifications to the object), but that may not be the most Go idiomatic approach, I'll embed the structure then. |
@overbool Want to take over this one? This should be ported to the |
@schomatis Yes. I'm also interested in this. |
Great! Ping me if you have any trouble porting the diff. |
As suggested in #5094 (comment).
Closes #5094.