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
+3.5k Golang : Fix go-cron set time not working issue
+8.9k Golang : Gorilla web tool kit schema example
+8.4k Prevent Write failed: Broken pipe problem during ssh session with screen command
+6.6k Elasticsearch : Shutdown a local node
+16k Golang : How to login and logout with JWT example
+5.9k Unix/Linux : Get reboot history or check when was the last reboot date
+6.9k Swift : substringWithRange() function example
+15.2k Golang : Search folders for file recursively with wildcard support
+9k Golang : Gaussian blur on image and camera video feed examples
+5.3k Responsive Google Adsense
+25.4k Golang : Storing cookies in http.CookieJar example
+17.1k Golang : Set up source IP address before making HTTP request