In case of an error, I tried to return nil , which throws an error:
nil
cannot use nil as type time.Time in return argument
What is the zero value for time.Time ?
zero
time.Time
Calling an empty literal struct time.Time will return a null date. Thus, for the following print statement:
fmt.Println(time.Time{})
Output:
0001-01-01 00:00:00 +0000 UTC
For completeness, official documentation expressly states:
Zero value of type Time - January 1, year 1, 00: 00: 00.00.000000000 UTC.
Instead, you should use the Time.IsZero () function:
func (Time) IsZero func (t Time) IsZero() bool IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
Zero value for time. Time 0001-01-01 00:00:00 +0000 UTC See http://play.golang.org/p/vTidOlmb9P