Ver código fonte

fix golint issues in core/timex (#517)

Kevin Wan 4 anos atrás
pai
commit
ef146cf5ba
4 arquivos alterados com 10 adições e 0 exclusões
  1. 1 0
      core/sysx/host.go
  2. 4 0
      core/timex/relativetime.go
  3. 1 0
      core/timex/repr.go
  4. 4 0
      core/timex/ticker.go

+ 1 - 0
core/sysx/host.go

@@ -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
 }

+ 4 - 0
core/timex/relativetime.go

@@ -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())
 }

+ 1 - 0
core/timex/repr.go

@@ -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))
 }

+ 4 - 0
core/timex/ticker.go

@@ -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),