abujehad139 / google-api-go-client

Automatically exported from code.google.com/p/google-api-go-client
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Support batch requests #29

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For a description of how batching works, see e.g.
https://developers.google.com/coordinate/v1/batch

It seems to be something that works on many if not all APIs.

I haven't decided exactly what the best way to handle it would be, but it seems 
like one might be able to construct an http.Client which transparently did 
batching.  When a Dial is done on the transport, it returns a conn whose other 
end is actually a local piece of code reading the HTTP request and adding it to 
the batch; then when the pseudo-Client's "Release" method (or similar) is 
called, all queued requests are assembled, sent, and then distributed back out 
to the waiting net.Conns.  Magic :).

The less magical way would be to generate additional APIs along the lines of

func (WhateverCall) AddTo(b Batch) (*Result, *error) { ... }

and then the Batch would have a Do which assembled the requests, decoded the 
responses into the pointers, etc.  I'm not sure how I feel about the 
pointer-to-error, though.

The up-shot of the first is that you can e.g. request a list of IDs, spin up a 
goroutine for each, and then every 100ms or so release the batch queries until 
all of the goroutines are done doing their work.  They would see it as a 
sequential request.  The up-shot of the second is that the batching is explicit 
in the code, but it seems a lot harder to use.

I might play around with this at some point if you think it's a good idea.

Original issue reported on code.google.com by kev...@google.com on 16 Apr 2013 at 3:50