func (c *TwitterApi) throttledQuery() {
	for q := range c.queryQueue {
		url := q.url
		form := q.form
		data := q.data  
		method := q.method
		response_ch := q.response_ch
		if c.bucket != nil {
			<-c.bucket.SpendToken(1)
		}
		err := c.execQuery(url, form, data, method)
		if err != nil {
			if apiErr, ok := err.(*ApiError); ok {
				if isRateLimitError, nextWindow := apiErr.RateLimitCheck(); isRateLimitError && !c.returnRateLimitError {
					c.Log.Info(apiErr.Error())
					go func(q query) {
						c.queryQueue <- q
					}(q)
					delay := nextWindow.Sub(time.Now())
					<-time.After(delay)
					if c.bucket != nil {
						c.bucket.Drain()
					}
					continue
				}
			}
		}
		response_ch <- response{data, err}
	}
}
throttledQuery executes queries and automatically throttles them according to SECONDS_PER_QUERY
It is the only function that reads from the queryQueue for a particular *TwitterApi struct
package anaconda
import (
	"compress/zlib"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
	"time"
	"github.com/ChimeraCoder/tokenbucket"
	"github.com/garyburd/go-oauth/oauth"
)
const (
	_GET          = iota
	_POST         = iota
	_DELETE       = iota
	_PUT          = iota
	BaseUrlV1     = "https://api.twitter.com/1"
	BaseUrl       = "https://api.twitter.com/1.1"
	UploadBaseUrl = "https://upload.twitter.com/1.1"
)
var (
	oauthCredentials oauth.Credentials
)
type TwitterApi struct {
	oauthClient          oauth.Client
	Credentials          *oauth.Credentials
	queryQueue           chan query
	bucket               *tokenbucket.Bucket
	returnRateLimitError bool
	HttpClient           *http.Client
	Log Logger
	baseUrl string
}
type query struct {
	url         string
	form        url.Values
	data        interface{}
	method      int
	response_ch chan response
}
type response struct {
	data interface{}
	err  error
}
const DEFAULT_DELAY = 0 * time.Second
const DEFAULT_CAPACITY = 5
func NewTwitterApi(access_token string, access_token_secret string) *TwitterApi {
	queue := make(chan query)
	c := &TwitterApi{
		oauthClient: oauth.Client{
			TemporaryCredentialRequestURI: "https://api.twitter.com/oauth/request_token",
			ResourceOwnerAuthorizationURI: "https://api.twitter.com/oauth/authenticate",
			TokenRequestURI:               "https://api.twitter.com/oauth/access_token",
			Credentials:                   oauthCredentials,
		},
		Credentials: &oauth.Credentials{
			Token:  access_token,
			Secret: access_token_secret,
		},
		queryQueue:           queue,
		bucket:               nil,
		returnRateLimitError: false,
		HttpClient:           http.DefaultClient,
		Log:                  silentLogger{},
		baseUrl:              BaseUrl,
	}
	go c.throttledQuery()
	return c
}
func NewTwitterApiWithCredentials(access_token string, access_token_secret string, consumer_key string, consumer_secret string) *TwitterApi {
	api := NewTwitterApi(access_token, access_token_secret)
	api.oauthClient.Credentials.Token = consumer_key
	api.oauthClient.Credentials.Secret = consumer_secret
	return api
}
func SetConsumerKey(consumer_key string) {
	oauthCredentials.Token = consumer_key
}
func SetConsumerSecret(consumer_secret string) {
	oauthCredentials.Secret = consumer_secret
}
func (c *TwitterApi) ReturnRateLimitError(b bool) {
	c.returnRateLimitError = b
}
func (c *TwitterApi) EnableThrottling(rate time.Duration, bufferSize int64) {
	c.bucket = tokenbucket.NewBucket(rate, bufferSize)
}
func (c *TwitterApi) DisableThrottling() {
	c.bucket = nil
}
func (c *TwitterApi) SetDelay(t time.Duration) {
	c.bucket.SetRate(t)
}
func (c *TwitterApi) GetDelay() time.Duration {
	return c.bucket.GetRate()
}
func (c *TwitterApi) SetBaseUrl(baseUrl string) {
	c.baseUrl = baseUrl
}
func (c *TwitterApi) AuthorizationURL(callback string) (string, *oauth.Credentials, error) {
	tempCred, err := c.oauthClient.RequestTemporaryCredentials(http.DefaultClient, callback, nil)
	if err != nil {
		return "", nil, err
	}
	return c.oauthClient.AuthorizationURL(tempCred, nil), tempCred, nil
}
func (c *TwitterApi) GetCredentials(tempCred *oauth.Credentials, verifier string) (*oauth.Credentials, url.Values, error) {
	return c.oauthClient.RequestToken(http.DefaultClient, tempCred, verifier)
}
func defaultValues(v url.Values) url.Values {
	if v == nil {
		v = url.Values{}
	}
	v.Set("tweet_mode", "extended")
	return v
}
func cleanValues(v url.Values) url.Values {
	if v == nil {
		return url.Values{}
	}
	return v
}
func (c TwitterApi) apiGet(urlStr string, form url.Values, data interface{}) error {
	form = defaultValues(form)
	resp, err := c.oauthClient.Get(c.HttpClient, c.Credentials, urlStr, form)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return decodeResponse(resp, data)
}
func (c TwitterApi) apiPost(urlStr string, form url.Values, data interface{}) error {
	resp, err := c.oauthClient.Post(c.HttpClient, c.Credentials, urlStr, form)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return decodeResponse(resp, data)
}
func (c TwitterApi) apiDel(urlStr string, form url.Values, data interface{}) error {
	resp, err := c.oauthClient.Delete(c.HttpClient, c.Credentials, urlStr, form)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return decodeResponse(resp, data)
}
func (c TwitterApi) apiPut(urlStr string, form url.Values, data interface{}) error {
	resp, err := c.oauthClient.Put(c.HttpClient, c.Credentials, urlStr, form)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	return decodeResponse(resp, data)
}
func decodeResponse(resp *http.Response, data interface{}) error {
	defer resp.Body.Close()
	if resp.Header.Get("Content-Encoding") == "deflate" {
		var err error
		resp.Body, err = zlib.NewReader(resp.Body)
		if err != nil {
			return err
		}
	}
	if strings.HasSuffix(resp.Request.URL.String(), "upload.json") {
		if resp.StatusCode == 204 {
			return nil
		}
		if resp.StatusCode < 200 || resp.StatusCode >= 300 {
			return newApiError(resp)
		}
	} else if resp.StatusCode != 200 {
		return newApiError(resp)
	}
	return json.NewDecoder(resp.Body).Decode(data)
}
func NewApiError(resp *http.Response) *ApiError {
	body, _ := ioutil.ReadAll(resp.Body)
	return &ApiError{
		StatusCode: resp.StatusCode,
		Header:     resp.Header,
		Body:       string(body),
		URL:        resp.Request.URL,
	}
}
func (c TwitterApi) execQuery(urlStr string, form url.Values, data interface{}, method int) error {
	switch method {
	case _GET:
		return c.apiGet(urlStr, form, data)
	case _POST:
		return c.apiPost(urlStr, form, data)
	case _DELETE:
		return c.apiPost(urlStr, form, data)
	case _PUT:
		return c.apiPost(urlStr, form, data)
	default:
		return fmt.Errorf("HTTP method not yet supported")
	}
}