- 
                Notifications
    You must be signed in to change notification settings 
- Fork 32
feat: Add support to disable stringer #40
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
Conversation
| Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! | 
| I like the idea, but the DisableMethods name pulled out of spew is not easy to understand. So I'm fine with the implementation, except the name. Also, I like what you pulled from spew, because it shows that DisableMethods was about  Maybe there is something to do with Error too, but I'm unsure. otherwise  Wording is tough, so let's wait for feedbacks here | 
| 
 
 I actually called this  But I don't have that strong feeling, if  | 
| 
 @ccoVeille I'd recommend  | 
| 
 I echo the sentiments for  | 
Currently `godump` always uses the stringer interface if defined. This is not always desirable if you want to check the internals of a type. This adds a feature with the same name used for [`spew`][spew] (`DisableMethods`) which can be set to true to disable this feature. [spew]: https://github.com/davecgh/go-spew/blob/8991bc29aa16c548c550c7ff78260e27b9ab7c73/spew/config.go#L52-L54
63a167e    to
    53674c2      
    Compare
  
    53674c2    to
    781f048      
    Compare
  
    | func (d *Dumper) asStringer(v reflect.Value) string { | ||
| if d.disableStringer { | ||
| return "" | ||
| } | 
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.
Do we really want to return blank? I would think we would at least want the following to return the raw "non-stringer" value from the struct ? I could be wrong here
	if !val.CanInterface() {
		val = forceExported(val)
	}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.
That's interesting, I'm not sure I follow when and what that is supposed to work 🤔
The test for this is on a private field in a private struct and it seems to work as expected by returning the empty string to continue the processing in printValue to figure out the type.
I'll do some more testing but feel free to add an example on when this would be needed if you know how to! Thanks!
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.
Didn't get too much time, but quickly glancing at the code, it looks like the need for this forced export is so we can call val.Interface().(fmt.Stringer) on private fields. But we won't end up in this path if we're not looking for strings so we don't have a use of what's returned from forceExported.
We do something similar at printValue for struct fields which I think is what you're referring to to show private fields. But it's not important that we force a value that can call Interface() here either because we don't do that.
I don't think we need to do any change at least to get expected behavior. I updated the test to ensure we see the private field and I also removed one place where we call asStringer and look for the empty string which can be done recursively instead.
Currently
godumpalways uses the stringer interface if defined. This is not always desirable if you want to check the internals of a type.This adds a feature with the same name used for
spew(DisableMethods) which can be set to true to disable this feature.