fix golint issues in core/timex (#517)
This commit is contained in:
@@ -16,6 +16,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// Hostname returns the name of the host, if no hostname, a random id is returned.
|
||||
func Hostname() string {
|
||||
return hostname
|
||||
}
|
||||
|
||||
@@ -5,14 +5,18 @@ import "time"
|
||||
// Use the long enough past time as start time, in case timex.Now() - lastTime equals 0.
|
||||
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 {
|
||||
return time.Since(initTime)
|
||||
}
|
||||
|
||||
// Since returns a diff since given d.
|
||||
func Since(d time.Duration) time.Duration {
|
||||
return time.Since(initTime) - d
|
||||
}
|
||||
|
||||
// Time returns current time, the same as time.Now().
|
||||
func Time() time.Time {
|
||||
return initTime.Add(Now())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ReprOfDuration returns the string representation of given duration in ms.
|
||||
func ReprOfDuration(duration time.Duration) string {
|
||||
return fmt.Sprintf("%.1fms", float32(duration)/float32(time.Millisecond))
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Ticker interface wraps the Chan and Stop methods.
|
||||
Ticker interface {
|
||||
Chan() <-chan time.Time
|
||||
Stop()
|
||||
}
|
||||
|
||||
// FakeTicker interface is used for unit testing.
|
||||
FakeTicker interface {
|
||||
Ticker
|
||||
Done()
|
||||
@@ -30,6 +32,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// NewTicker returns a Ticker.
|
||||
func NewTicker(d time.Duration) Ticker {
|
||||
return &realTicker{
|
||||
Ticker: time.NewTicker(d),
|
||||
@@ -40,6 +43,7 @@ func (rt *realTicker) Chan() <-chan time.Time {
|
||||
return rt.C
|
||||
}
|
||||
|
||||
// NewFakeTicker returns a FakeTicker.
|
||||
func NewFakeTicker() FakeTicker {
|
||||
return &fakeTicker{
|
||||
c: make(chan time.Time, 1),
|
||||
|
||||
Reference in New Issue
Block a user