Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

fix: String method on the OptionalString #153

Merged
merged 3 commits into from
Oct 29, 2021
Merged

Conversation

marten-seemann
Copy link
Member

@marten-seemann marten-seemann commented Oct 29, 2021

+ test fixes

types.go Outdated
@@ -358,9 +358,9 @@ func (p *OptionalString) UnmarshalJSON(input []byte) error {

func (p OptionalString) String() string {
if p.value == nil {
return "default"
return ""
Copy link
Member

@lidel lidel Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current convention is that String() methods return default to state that the value is default:

return "default"

return "default"

return "default"

I think we shoulkd switch it back and to do the same here. Better to be explicit and consistent here.
( alternative was to change it everywhere to something more explicit like <default> )

Suggested change
return ""
return "default"

If you want to get "" on the consumer side of things, you want to use WithDefault("") – see
https://github.com/ipfs/go-ipfs/blob/228570814df94ab7bdd9052a4c705c1bf4c7f0b9/core/node/groups.go#L321

Copy link
Member

@lidel lidel Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to "default" in 5861089

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging for the sake of merging useful fixes and new tests, thanks!

(I don't feel strongly about specifics of the default String(), only want things to be consistent across types, but don't want that discussion to slow down release. We can tackle it in a separate issue or a PR, if you feel strongly either way.)

@lidel lidel changed the title fix String method on the OptionalString fix: String method on the OptionalString Oct 29, 2021
@lidel lidel merged commit 7aa6b00 into master Oct 29, 2021
@lidel lidel deleted the fix-optionalstring-string branch October 29, 2021 15:21
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants