Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the zero for string?

Tags:

string

go

That's "" :

var s string
fmt.Println(s=="") // prints "true"

A string cannot be nil (but a *string can).

You can simply test

if stringId=="" {

To pass a zero string in stringID, use

k := NewKey(c, "kind", "", 0, p)

From the specification :

When memory is allocated to store a value, either through a declaration or a call of make or new, and no explicit initialization is provided, the memory is given a default initialization. Each element of such a value is set to the zero value for its type: false for booleans, 0 for integers, 0.0 for floats, "" for strings, and nil for pointers, functions, interfaces, slices, channels, and maps.