At the risk of appearing low-tech, a much more simple, Goroutine-safe solution for dealing with "now-dependent" code:
type NowFunc func() time.Time
func getGreeting(nowFunc NowFunc) string {
now := nowFunc()
if now.Hour() < 12 {
return "Good Morning"
}
return "Good day"
}And just pass in `time.Now` in for live code, and your own inline function for simulating a time in tests.