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

Access to actual JSON payload. #18

Open
akshayrawat opened this issue Apr 14, 2014 · 5 comments
Open

Access to actual JSON payload. #18

akshayrawat opened this issue Apr 14, 2014 · 5 comments

Comments

@akshayrawat
Copy link

I'm new to Go, and am trying to figure out things. One thing which made goworker a bit hard to use was that the worker get an args ... interface{} as the payload. This means that the args would need to be manually type asserted to build the actual object structures. This can get cumbersome when its a complex JSON payload.

I had asked if there was another way to do this on SO, but it seems like there isn't any.

If access to the JSON is provided, then a struct can be passed to unmarshal to build that type.

Let me know, and thanks for this brilliant package.

@benmanns
Copy link
Owner

Currently, there's no way to access the JSON payload except through the args interface.

I am investigating a way to specify the type of object you want for a worker function. Possibly something along the lines of:

goworker.RegisterType("MyClass", myFunc, &MyType{})

where you would only do one type assertion within myFunc for args.(MyType).

Alternatively, we could use json.RawMessage and have the function do the unmarshalling, but this, too, would require some reworking. Possibly something along the lines of:

goworker.RegisterRaw("MyClass", myFunc)

then within the worker

var val MyType
json.Unmarshal(raw, val)

What would work better for you?

@akshayrawat
Copy link
Author

I suppose the RegisterRaw approach is a little more flexible (and relevant to my use-case). I have a nested map of arrays of maps. I was just thinking about using something like go-simplejson to unmarshal it, if access to raw JSON was there.

@wricardo
Copy link

+1 for RegisterRaw

@rjrobinson
Copy link

👍 As well. I think this will help with a lot of bigger payloads complex payloads.

My workaround was actually to just save a temp .json file, and have the goworker trigger a download from s3, and unmarshal it into a struct. Though hacky, cut down time on building lots of workers.

@snobb
Copy link

snobb commented Feb 8, 2021

👍 on RegisterRaw. My workaround was to Marshal the payload back and then Unmarshal to my the actual struct, which is quite wasteful.

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

5 participants