Sling Academy
Home/Golang/Common errors in Go and how to fix them

Common errors in Go and how to fix them

This series of tutorials helps you solve common problems and errors you may encounter when developing Go applications.

1 How to cancel a hanging operation in Go

2 Handling unmarshal JSON with unknown fields in Go

3 Cannot convert []string to []interface {} in Go

4 Fixing Go error: cannot use X (type Y) as type Z in assignment

5 Fixing Go error: nil pointer dereference

6 Fixing Go error: index out of range

7 Fixing Go error: panic: runtime error: invalid memory address or nil pointer dereference

8 Fixing Go error: imported and not used

9 Fixing Go error: declared and not used

10 Fixing Go error: type does not implement interface

11 Fixing Go error: cannot assign to struct field in map

12 Fixing Go error: fatal error: all goroutines are asleep - deadlock!

13 Fixing Go error: missing return

14 Fixing Go error: too many arguments in call to function

15 Fixing Go error: assignment to entry in nil map

16 Fixing Go error: invalid argument for len

17 Fixing Go error: type assertion error

18 Fixing Go error: invalid operation: mismatched types

19 Fixing Go error: invalid memory address or nil pointer dereference

20 Fixing Go error: slice bounds out of range

21 Fixing Go error: division by zero

22 Fixing Go error: duplicate key in map literal

23 Fixing Go error: chan send on closed channel

24 Fixing Go error: chan receive on closed channel

25 Fixing Go error: attempt to close closed channel

26 Fixing Go error: interface conversion: interface is nil, not type

27 Fixing Go error: undefined: variable or package

28 Fixing Go error: cannot use untyped nil in assignment

29 Fixing Go error: no new variables on left side of :=

30 Fixing Go error: use of untyped nil

31 Fixing Go error: unexpected newline, expecting comma or }

32 Fixing Go error: redeclared in this block

33 Fixing Go error: undeclared name: X

34 Fixing Go error: syntax error: unexpected X, expecting Y

35 Fixing Go error: array index must be non-negative integer constant

36 Fixing Go error: assignment mismatch: X variables but Y values

37 Fixing Go error: method has pointer receiver, not called with pointer

38 Fixing Go error: cannot compare X (type Y) with Z (type W)

39 Fixing Go error: assignment to constant variable

40 Fixing Go error: attempted to use nil slice

41 Fixing Go error: copy argument must have slice type

42 Fixing Go error: method redeclared with different receiver type