Skip to content

Conversation

@KrzysztofKornalewski-Reply
Copy link

@KrzysztofKornalewski-Reply KrzysztofKornalewski-Reply commented Jun 10, 2025

Adding LegacyStringToSliceHookFunc for dependent repository.
#100

}
}

func LegacyStringToSliceHookFunc(sep string) DecodeHookFunc {

Choose a reason for hiding this comment

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

@KrzysztofKornalewski-Reply Is this sufficient or do we also need to handle lists as well? I think the example in #64 is "" to []int{}.

Choose a reason for hiding this comment

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

Yes this should be sufficient, as you know from this migration PR:
openbao/openbao#290
There are two errors, and based on my tests and debugging, this approach resolves both. When I manually added LegacyStringToSliceHookFunc, both failed test cases were resolved.

The conversion problem for "1,2,3," for example, occurs because the new Hook implementation of StringToSliceHookFunc() only works when the target is a slice of strings. Previously, it worked for any slices.

About "" to []int{} it also occurs because of workflow has changed in StringToSliceHookFunc().

They also store this solution locally in spf13/viper.
https://github.com/spf13/viper/blob/260b8e9a3c75f49c374251f10fa1529d9e704b6a/viper.go#L1000

Choose a reason for hiding this comment

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

@KrzysztofKornalewski-Reply Ahh, I see now. Makes sense, thank you!

Choose a reason for hiding this comment

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

@KrzysztofKornalewski-Reply In the meantime, you could also open this as a PR against OpenBao I think, and see if that solves the issues with PR 290 :-)

@KrzysztofKornalewski-Reply
Copy link
Author

@sagikazarmark can I get a review?

Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

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

Thanks @KrzysztofKornalewski-Reply !

I had one comment

}
}

func LegacyStringToSliceHookFunc(sep string) DecodeHookFunc {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a comment why this is added?

I have added this to Viper: https://github.com/spf13/viper/blob/master/viper.go#L1000

I also wonder if it would make sense to call it StringToWeakSlice instead (as in Viper).

Choose a reason for hiding this comment

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

I wanted to migrate from the old mapstructure to the go-viper/mapstruct without additional dependencies. I'm wondering if the official approach requires importing the spy13/viper repository to use the handler you mentioned above.

If yes, then okay.

Copy link
Author

@KrzysztofKornalewski-Reply KrzysztofKornalewski-Reply Jun 16, 2025

Choose a reason for hiding this comment

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

But spy13/viper require some additional changes, we don't use Viper structure.
func (v *Viper) defaultDecoderConfig

We would like to use it as a normal function.

Copy link
Member

Choose a reason for hiding this comment

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

@KrzysztofKornalewski-Reply that's just an example. It's basically the same function that you submitted.

I copied it earlier to Viper to keep backward compatibility.

I linked it as an example to demonstrate:

  • what kind of comment I asked for
  • what I called the function there

Legacy feels outdated, fragile.

Choose a reason for hiding this comment

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

@sagikazarmark Is there any chance to keep this legacy hook in a repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants