panic: runtime error: invalid memory address or nil pointer dereference

panic: runtime error: invalid memory address or nil pointer dereference

我目前正在使用 Go 的 Soundcloud 包装器,我想打印用户的关注者,但这是我第一次遇到指针问题。

构建错误后

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0xc9c26]

代码

package main

import (
    "fmt"
    "github.com/njasm/gosoundcloud"
)


func main() {
    //  callback url is optional - nil in example
    s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)
    var userID uint64 = 1
    member, err := s.GetUser(userID)
    if err != nil {
               panic(err)
     }
    fmt.Println(member.Followers)
}

建造后

goroutine 1 [running]:
panic(0x3508c0, 0xc82000a0b0)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
net/http.(*Client).doFollowingRedirects(0x0, 0xc8200d0000, 0x4611c8, 0x0, 0x0, 0x0)
    /usr/local/go/src/net/http/client.go:429 +0x66
net/http.(*Client).Do(0x0, 0xc8200d0000, 0x8, 0x0, 0x0)
    /usr/local/go/src/net/http/client.go:188 +0xff
github.com/njasm/gosoundcloud.(*SoundcloudApi).do(0xc8200c8720, 0xc8200d0000, 0xc820012f00, 0x0, 0x0)
    /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:217 +0x4b
github.com/njasm/gosoundcloud.(*SoundcloudApi).Get(0xc8200c8720, 0xc820012f00, 0x22, 0x0, 0x1, 0x0, 0x0)
    /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:92 +0xe1
github.com/njasm/gosoundcloud.(*SoundcloudApi).GetUser(0xc8200c8720, 0x1, 0x417a80, 0x0, 0x0)
        /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:276 +0xc6
main.main()
        /Users/ManuelDao/Documents/GoBot/src/GoBot/GoBot.go:24 +0x70
exit status 2

我以前从未使用过这个库,但你好像忘了验证自己。

s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)
if err = s.PasswordCredentialsToken("your_email@something.com", "your_password"); err != nil {
    // handle err
}

也许是这样的?