I am building some functionality that seems to fit best in the existing Go
packages. For a very simple example related to a previous thread I started,
where I need to sleep till pretty close to the boundary of the next N
seconds into the future,
func DurationTillBoundary(interval int64) time.Duration {
now := time.Now()
// This many ns till the next second boundary
ns := time.Second.Nanoseconds() - int64(now.Nanosecond())
// This many sec till the next desired seconds
sec := interval - (now.Unix() % interval) - 1
return time.Duration(sec * time.Second.Nanoseconds() + ns)*
time.Nanosecond
}
That's what I wrote in my little throwaway script, but what I should have
written, I believe, is
func (t *time.Time) DurationTillBoundary(....
This feels like it belongs in the time package in my own package hierarchy.
Should I do that? That would effectively add onto the existing time
package. Or maybe I should add a new time/timeutil package instead? Or
should I root my package hierarchy like in Java, where I would do
org.MyCompany.time instead? What are your experiences and what practices do
you suggest? I expect that I will eventually have a very large codebase
with probably hundreds of packages, so now is the best time for me to
figure out how to do this.
I have several other examples, such as container/fifo and some things that
ought to go into math or mathutil.
Thanks
Boris
--