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
+10.5k Android Studio : Simple input textbox and intercept key example
+24.5k Golang : Time slice or date sort and reverse sort example
+11.5k SSL : The certificate is not trusted because no issuer chain was provided
+12.2k Golang : How to display image file or expose CSS, JS files from localhost?
+11.7k Golang : GTK Input dialog box examples
+7.9k Golang : Grayscale Image
+18.8k Golang : How to make function callback or pass value from function as parameter?
+6k Java : Human readable password generator
+11k Golang : Create S3 bucket with official aws-sdk-go package
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+6k Golang : Debug with Godebug