my code works perfectly until I want to scale it using many concurrent calls. It works by asking the client a Get request.
This is what I'm getting:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x400da9]
goroutine 125 [running]:
runtime.panic(0x697480, 0x850d13)
/usr/lib/go/src/pkg/runtime/panic.c:279 +0xf5
main.concurrent(0x25e5)
/home/maker/go/src/GoBot/GoBot.go:19 +0x1a9
created by main.main
/home/maker/go/src/GoBot/GoBot.go:51 +0x224
I think I'm not properly handling the error and when making a lot of requests it crashes.
func concurrent(n uint64) {
for i := n; i < n+11; i++ {
member, err := s.GetUser(i)
output <- fmt.Sprint(member.Username) //This is line 19 that triggers the error
if err != nil && member != nil {
continue
}
}
defer wg.Done()
}
How can I solve this? References for s.GetUser here: https://github.com/njasm/gosoundcloud/blob/master/soundcloud.go#L274