Skip to content
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

Support typed setter functions #17

Closed
theherk opened this issue Dec 13, 2016 · 5 comments
Closed

Support typed setter functions #17

theherk opened this issue Dec 13, 2016 · 5 comments
Milestone

Comments

@theherk
Copy link

theherk commented Dec 13, 2016

I'm not sure if I'm missing something, but it seems you can only set properties to strings. I know you can read other types, but what if I was to SetInt()?

@magiconair
Copy link
Owner

@theherk Good point. I think adding corresponding helper methods for the supported types makes sense.

@magiconair magiconair changed the title Is it possible to Set non string values? Support typed setter functions Dec 14, 2016
magiconair added a commit that referenced this issue Jan 13, 2017
This patch adds typed setter functions for all supported
getter functions.
magiconair added a commit that referenced this issue Jan 13, 2017
This patch adds typed setter functions for all supported
getter functions.
@magiconair
Copy link
Owner

I've added SetBool, SetInt, SetInt64, SetFloat64, SetString, SetDuration, SetUint and SetUint64 to complement the existing getter functions. I think a single SetValue(key string, value interface{}) error might make more sense. What do you think?

@theherk
Copy link
Author

theherk commented Jan 13, 2017

I think you're right. I felt more confident about my thoughts when I opened the issue, but that faded. I think the SetValue makes good sense.

magiconair added a commit that referenced this issue Jan 16, 2017
This patch provides a generic SetValue() method
which accepts the value as interface{} and then
stores the default representation as defined by
fmt.Sprintf("%v") as value.
@magiconair
Copy link
Owner

@theherk Added a patch for the SetValue method but I'd still like to think about it a bit more. SetValue just calls Set with fmt.Sprintf("%v", value) as value.

@magiconair
Copy link
Owner

%v also uses the String() method, if defined.

@magiconair magiconair added this to the 1.7.3 milestone Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants