gomodule / oauth1

OAuth 1.0 client package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Twitter example panics

kjk opened this issue · comments

In Twitter example, RequestToken() and RequestTemporaryCredentials() pass nil as first arg (http client), which causes a panic on 1.4.2

It should be http.DefaultClient like in other examples.

I cannot reproduce the problem. Can you post the stack trace from the panic?

Note: this is from my own code, copied more or less verbatim from Twitter example. The crash is:

2015/03/16 11:08:23 http: panic serving [::1]:62725: runtime error: invalid memory address or nil pointer dereference
goroutine 9 [running]:
net/http.func·011()
    /usr/local/Cellar/go/1.4.2/libexec/src/net/http/server.go:1130 +0xbb
net/http.(*Client).doFollowingRedirects(0x0, 0xc20801fa00, 0x604ec8, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/1.4.2/libexec/src/net/http/client.go:304 +0x62
net/http.(*Client).Post(0x0, 0x5ad610, 0x2b, 0x58a910, 0x21, 0x8633a8, 0xc20800b780, 0x3a47c0, 0x0, 0x0)
    /usr/local/Cellar/go/1.4.2/libexec/src/net/http/client.go:441 +0x10d
net/http.(*Client).PostForm(0x0, 0x5ad610, 0x2b, 0xc2080acff0, 0x5ad610, 0x0, 0x0)
    /usr/local/Cellar/go/1.4.2/libexec/src/net/http/client.go:461 +0x11c
github.com/garyburd/go-oauth/oauth.(*Client).request(0x775f80, 0x0, 0x0, 0x5ad610, 0x2b, 0xc2080acff0, 0xc, 0x25, 0x0, 0x0)
    /var/folders/v9/sstxzky559j1kp4tjsb3bzh80000gq/T/gdep/rev/3b/723ab4b7bd12769c5a3b3de84dbf03e51e4fbb/src/github.com/garyburd/go-oauth/oauth/oauth.go:396 +0xcd
github.com/garyburd/go-oauth/oauth.(*Client).RequestTemporaryCredentials(0x775f80, 0x0, 0xc2089a61c0, 0x31, 0x0, 0x10, 0x0, 0x0)
    /var/folders/v9/sstxzky559j1kp4tjsb3bzh80000gq/T/gdep/rev/3b/723ab4b7bd12769c5a3b3de84dbf03e51e4fbb/src/github.com/garyburd/go-oauth/oauth/oauth.go:434 +0x2ed
main.handleLoginTwitter(0x863078, 0xc208064a00, 0xc20801f860)
    /Users/kjk/src/go/src/github.com/kjk/quicknotes/handle_login.go:180 +0x2e6
kjk$ go version
go version go1.4.2 darwin/amd64

The crash goes away if I change nil => http.DefaultClient:

-       tempCred, err := oauthTwitterClient.RequestTemporaryCredentials(nil, cb, nil)
+       tempCred, err := oauthTwitterClient.RequestTemporaryCredentials(http.DefaultClient, cb, nil)

The example depends on a3dfb38. You are using an older version.

Sorry about that. I thought I was using the latest because I did go get -u but I have older version pinned in my Godeps file. No bug then.