magiconair / properties

Java properties scanner for Go
BSD 2-Clause "Simplified" License
323 stars 77 forks source link

Support typed setter functions #17

Closed theherk closed 7 years ago

theherk commented 7 years ago

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 commented 7 years ago

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

magiconair commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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