github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/readability/val-and-error.go (about) 1 // +build OMIT 2 3 package sample // OMIT 4 5 import ( // OMIT 6 "errors" // OMIT 7 "time" // OMIT 8 ) // OMIT 9 10 var ( 11 ErrDurationUnterminated = errors.new("duration: unterminated") 12 ErrNoDuration = errors.New("duration: not found") 13 ErrNoIteration = errors.New("duration: not interation") 14 ) 15 16 func (it Iterator) DurationAt() (time.Duration, error) { // HL 17 // some code 18 switch durationUsec := m.GetDurationUsec(); durationUsec { 19 case -1: 20 return 0, ErrDurationUnterminated // HL 21 case -2: 22 return 0, ErrNoDuration // HL 23 default: 24 return time.Duation(durationUsec) * time.Microsecond, nil // HL 25 } 26 return 0, ErrNoIteration // HL 27 }