fix golint issues in core/timex (#517)

master
Kevin Wan 4 years ago committed by GitHub
parent 04b0f26182
commit ef146cf5ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,7 @@ func init() {
} }
} }
// Hostname returns the name of the host, if no hostname, a random id is returned.
func Hostname() string { func Hostname() string {
return hostname return hostname
} }

@ -5,14 +5,18 @@ import "time"
// Use the long enough past time as start time, in case timex.Now() - lastTime equals 0. // Use the long enough past time as start time, in case timex.Now() - lastTime equals 0.
var initTime = time.Now().AddDate(-1, -1, -1) var initTime = time.Now().AddDate(-1, -1, -1)
// Now returns a relative time duration since initTime, which is not important.
// The caller only needs to care about the relative value.
func Now() time.Duration { func Now() time.Duration {
return time.Since(initTime) return time.Since(initTime)
} }
// Since returns a diff since given d.
func Since(d time.Duration) time.Duration { func Since(d time.Duration) time.Duration {
return time.Since(initTime) - d return time.Since(initTime) - d
} }
// Time returns current time, the same as time.Now().
func Time() time.Time { func Time() time.Time {
return initTime.Add(Now()) return initTime.Add(Now())
} }

@ -5,6 +5,7 @@ import (
"time" "time"
) )
// ReprOfDuration returns the string representation of given duration in ms.
func ReprOfDuration(duration time.Duration) string { func ReprOfDuration(duration time.Duration) string {
return fmt.Sprintf("%.1fms", float32(duration)/float32(time.Millisecond)) return fmt.Sprintf("%.1fms", float32(duration)/float32(time.Millisecond))
} }

@ -8,11 +8,13 @@ import (
) )
type ( type (
// Ticker interface wraps the Chan and Stop methods.
Ticker interface { Ticker interface {
Chan() <-chan time.Time Chan() <-chan time.Time
Stop() Stop()
} }
// FakeTicker interface is used for unit testing.
FakeTicker interface { FakeTicker interface {
Ticker Ticker
Done() Done()
@ -30,6 +32,7 @@ type (
} }
) )
// NewTicker returns a Ticker.
func NewTicker(d time.Duration) Ticker { func NewTicker(d time.Duration) Ticker {
return &realTicker{ return &realTicker{
Ticker: time.NewTicker(d), Ticker: time.NewTicker(d),
@ -40,6 +43,7 @@ func (rt *realTicker) Chan() <-chan time.Time {
return rt.C return rt.C
} }
// NewFakeTicker returns a FakeTicker.
func NewFakeTicker() FakeTicker { func NewFakeTicker() FakeTicker {
return &fakeTicker{ return &fakeTicker{
c: make(chan time.Time, 1), c: make(chan time.Time, 1),

Loading…
Cancel
Save