-
Notifications
You must be signed in to change notification settings - Fork 435
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
Added ParsePrimitiveValue convenience function for users #38
Conversation
I'm not fan of using
You will do:
It is better in my view, and more explicit. |
I think that would be good idea as well, and I understand why you want to avoid However, many users are just going to throw those |
Well i need to keep library API consistent. When you call it using interface you should know the type, because if you provide different type program will panic. So it means that semantically Maybe i'm missing the point, and if so, pls provide full featured real world example of how you see it. |
The point is only convenience for a common use case, but I understand what you're saying and am not strongly pushing for this. Here's the example from my project, modified a bit so I'm not just copying company code here :):
The Again, I'm not adamant about this; I can make do with just the simpler convenience methods you suggest, and honestly I do like the simplicity of keeping everything explicit in this library. It's your call, I'm happy either way. |
Frankly i do not see need for helper
Your error checks basically do nothing, only return boolean value instead of error object. |
This assumes the code already knows what the ValueType of the value is, which is not the case in my code. As for the error checks, as I said, the interface is already defined, so I must return |
You've convinced me that the per-type parser methods ( |
Well, when you call Sorry if bothering you too much, but i'm really curious how people use library, its very important on design decisions. Thank you! |
My use of the |
I guess the bottom line is that the type isn't checked on the return value until much later, rather than in the code immediately after the |
I see, thank you! Let me think about it for some time :) |
As I said, I am now convinced that your suggestion is the better way here. I would like to refactor this PR to use per-type |
The keys parameter passed in to searchKeys are interpreted literally, however, and are not unescaped. If search key may contain escape sequences that should be unescaped, the calling code must handle this.
Users will often want to convert a
[]byte
returned byGet()
orArrayEach()
that represents a primitive value (Null
,Boolean
,Number
,String
) into the corresponding Go type (nil
,bool
,float64
,string
). This PR provides a convenience method,ParsePrimitiveValue([]byte) (interface{}, error)
, which performs this service for such users.Since this is just a convenience method,
Get()
, etc. are unchanged (except somegofmt
whitespace diff insearchKeys
...)