Golang : Null and nil value
Programmers coming from different programming languages to Golang might wonder how does one deal with NULL values. I put down these reminders below about NULL value for myself and maybe this can be useful to you as well.
Here you go :
Golang does not support NULL.
Nil is the equivalent of NULL in Golang.
All variables by default are initiated with the nil(zero) value.
Example usage of nil :
correctHash := sha1.New() fmt.Printf("%x \n", correctHash.Sum(nil))
Function returning nil will NOT compile,
// not OK func getName() string { return nil }
but returning nil to a pointer or reference (such as a struct) is ok and will compile.
type Person struct { name string } // OK func getName() *Person { return nil }
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8k Golang : Trim everything onward after a word
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error
+39.7k Golang : Remove dashes(or any character) from string
+5k JQuery : Calling a function inside Jquery(document) block
+22.1k Golang : Join arrays or slices example
+8.2k Golang : Routes multiplexer routing example with regular expression control
+19.8k Golang : Archive directory with tar and gzip
+14.9k Golang : Basic authentication with .htpasswd file
+14.6k Golang : Convert(cast) int to float example
+10k Golang : Get escape characters \u form from unicode characters
+9.2k Golang : does not implement flag.Value (missing Set method)