fix golint issues in core/utils (#520)

* fix golint issues in core/utils

* fix golint issues in core/trace

* fix golint issues in core/trace
This commit is contained in:
Kevin Wan
2021-02-26 16:20:47 +08:00
committed by GitHub
parent 2087ac1e89
commit f309e9f80c
8 changed files with 27 additions and 1 deletions

View File

@@ -7,32 +7,39 @@ import (
"github.com/tal-tech/go-zero/core/timex"
)
// A ElapsedTimer is a timer to track the elapsed time.
type ElapsedTimer struct {
start time.Duration
}
// NewElapsedTimer returns a ElapsedTimer.
func NewElapsedTimer() *ElapsedTimer {
return &ElapsedTimer{
start: timex.Now(),
}
}
// Duration returns the elapsed time.
func (et *ElapsedTimer) Duration() time.Duration {
return timex.Since(et.start)
}
// Elapsed returns the string representation of elapsed time.
func (et *ElapsedTimer) Elapsed() string {
return timex.Since(et.start).String()
}
// ElapsedMs returns the elapsed time of string on milliseconds.
func (et *ElapsedTimer) ElapsedMs() string {
return fmt.Sprintf("%.1fms", float32(timex.Since(et.start))/float32(time.Millisecond))
}
// CurrentMicros returns the current microseconds.
func CurrentMicros() int64 {
return time.Now().UnixNano() / int64(time.Microsecond)
}
// CurrentMillis returns the current milliseconds.
func CurrentMillis() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}

View File

@@ -2,6 +2,7 @@ package utils
import "github.com/google/uuid"
// NewUuid returns a uuid string.
func NewUuid() string {
return uuid.New().String()
}

View File

@@ -14,7 +14,7 @@ var replacer = stringx.NewReplacer(map[string]string{
"-": ".",
})
// operator compare returns true if the first field and the third field equation holds else false
// CompareVersions returns true if the first field and the third field are equal, otherwise false.
func CompareVersions(v1, op, v2 string) bool {
result := compare(v1, v2)
switch op {