There are many cases using nil in golang. For example:
func (u *URL) Parse(ref string) (*URL, error) {
refurl, err := Parse(ref)
if
nil
is a predeclared identifier in Go that represents zero values for pointers, interfaces, channels, maps, slices and function types.
nil
being the zero value of pointers and interfaces, uninitialized pointers and interfaces will be nil.
In Go, string can’t be nil
. A string doesn’t qualify to be assigned nil
.
a := nil // It will throw an error 'use of untyped nil'
var a *int = nil //It will work