I am getting the following error:
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/ytn/go/src/listner/start.go:19 +0x1a9 created by main.main /home/ytn/go/src/listner/init.go:51 +0x224
How can I fix it and What is the best practice to avoid this kind of error?
for i := n; i < n+11; i++ {
user, err := s.GetUser(i)
fmt.Sprint(user.Username) //This is line 19
if err != nil && user != nil {
continue
}
} defer wg.Done()