go-json-rest
go-json-rest copied to clipboard
Add support for casting environment variables to standard types.
What could be done is the Env map could be turned to a type and some convenience methods could be added for type casting, to avoid doing .(int) etc.
Something like Env.Int("param_name") or similar.
What would be the benefit over type assertions (eg: .(int)) ? This is the same amount of typing, and type assertions seem more Go-ish.
It's just nicer this way, you get autocomplete for some common types, also ForceType is also nice to have for convenience.
I've stolen this idea from https://godoc.org/github.com/garyburd/redigo/redis#hdr-Reply_Helpers , feel free to browse through it.
I thing the benefit is caller does not assert type itself. Maybe the method can be assert and return zero value when Env cannot assert.
Exactly!
On Wed, Jan 20, 2016 at 11:36 AM Thanabodee Charoenpiriyakij < [email protected]> wrote:
I thing the benefit is caller does not assert type itself. Maybe the method can be assert and return zero value when Env cannot assert.
— Reply to this email directly or view it on GitHub https://github.com/ant0ine/go-json-rest/issues/168#issuecomment-173165798 .