kurrik / twittergo

Twitter client library for go
Apache License 2.0
200 stars 31 forks source link

Connection timeout #14

Closed hangll closed 3 years ago

hangll commented 8 years ago

Recently, I got many following errors: Get https://api.twitter.com/1.1/trends/place.json?id=23424977&exclude=hashtags: read tcp 10. 240.0.7:45520->199.59.148.20:443: read: connection timed out

Should I set a longer timeout in http request (and how)? Or is it caused by other issues?

kurrik commented 8 years ago

I tried to design the twittergo client so that you can override the HTTP mechanism.

You should be able to set a new http.Client on the response from twittergo.NewClient: https://github.com/kurrik/twittergo/blob/master/twittergo.go#L83

return &Client{
                ...
        HttpClient: &http.Client{
            Transport: transport,
        },
                ...
    }

http.Client offers a Timeout attribute: https://golang.org/pkg/net/http/#Client

So it might be as easy as setting

client := twittergo.NewClient(...)
client.HttpClient.Timeout = ...

See if that helps at all. If not, then look into the various configuration options you have for http.Client. You should be able to instantiate any new http client and assign it to HttpClient before making the request.