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

Event.GetObjValue cannot handle arrays #503

Closed
timendez opened this issue Dec 19, 2017 · 5 comments
Closed

Event.GetObjValue cannot handle arrays #503

timendez opened this issue Dec 19, 2017 · 5 comments

Comments

@timendez
Copy link

Hi, I've spoken with Stripe support and the IRC channel over the course of a couple days, and we've come to the conclusion that it's not a bug, just not implemented yet. If that's not the case please let me know otherwise!

On the invoice created event, I'm trying to access the plan ID, but am having trouble because I'm not sure how to drill down into an array with GetObjValue. planID := event.GetObjValue("lines", "data[0]", "plan", "id") would be great, or "data", "0". Upon more research I've found that not every object in data will have a plan key, but I think this is a useful feature regardless.

Let me know if you have any plans to implement this, or if there is a better way to go about dealing with arrays located within events.

Thanks!

@ob-stripe
Copy link
Contributor

Hi @timendez! I haven't had time to dig properly, but from a quick glance at the code I think that you're correct and the GetObjValue function is currently unable to access arrays. I agree it would be a nice addition though!

cc @brandur-stripe to take a look and maybe open a quick PR if it's easy to implement :)

@brandur
Copy link
Contributor

brandur commented Dec 21, 2017

Hm, the implementation would be easy, but a potential problem is that "0" is ambiguous between the zero-index of an array/slice or a key named 0 in a map. I think the implementation would have to try to coerce to both possible types, which isn't amazing. On the other hand, GetObjValue is a pretty quick and dirty API in the first place, so maybe it doesn't matter that much.

@timendez
Copy link
Author

timendez commented Jan 3, 2018

can you implement it where "data[0]" is the parameter instead of "data", "0" then?

brandur-stripe pushed a commit that referenced this issue Jan 5, 2018
Modifies `event.GetObjValue` so that when specifying additional keys to
descend into, it's now possible to specify integer keys if the target
object is a slice of type `[]interface{}` (which should be what anything
coming out of event data deserializes to).

I initially expressed some concern about expanding this interface, but
given that the previous behavior would have been an outright panic, I
changed my mind and don't think it's too bad to add support for this
given that it's been requested by a user.

Fixes #503.
@brandur
Copy link
Contributor

brandur commented Jan 5, 2018

@timendez Thinking about this a little more, I think it's okay to implement this as you originally proposed. I took a stab in #506.

@timendez
Copy link
Author

timendez commented Jan 8, 2018

Awesome, thank you man 👍

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

No branches or pull requests

3 participants