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
+21.7k Curl usage examples with Golang
+30k Golang : How to get HTTP request header information?
+7.3k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+8.4k Golang : Emulate NumPy way of creating matrix example
+7.5k Golang : Accessing dataframe-go element by row, column and name example
+9.9k Golang : Detect number of active displays and the display's resolution
+10.4k Golang : Bcrypting password
+36.8k Golang : Save image to PNG, JPEG or GIF format.
+8.7k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+9.2k Golang : Handle sub domain with Gin
+38.3k Golang : Read a text file and replace certain words
+7.9k Golang : Generate human readable password