Commit c8c25549 authored by wangguoliang's avatar wangguoliang

should use time.Since instead of time.Now().Sub

Signed-off-by: 's avatarwgliang <liangcszzu@163.com>
parent d96289a8
...@@ -38,7 +38,7 @@ func (mi *MemoryItem) isExpire() bool { ...@@ -38,7 +38,7 @@ func (mi *MemoryItem) isExpire() bool {
if mi.lifespan == 0 { if mi.lifespan == 0 {
return false return false
} }
return time.Now().Sub(mi.createdTime) > mi.lifespan return time.Since(mi.createdTime) > mi.lifespan
} }
// MemoryCache is Memory cache adapter. // MemoryCache is Memory cache adapter.
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
// MethodParamOption defines a func which apply options on a MethodParam // MethodParamOption defines a func which apply options on a MethodParam
type MethodParamOption func(*MethodParam) type MethodParamOption func(*MethodParam)
// IsRequired indicates that this param is required and can not be ommited from the http request // IsRequired indicates that this param is required and can not be omitted from the http request
var IsRequired MethodParamOption = func(p *MethodParam) { var IsRequired MethodParamOption = func(p *MethodParam) {
p.required = true p.required = true
} }
......
...@@ -75,7 +75,7 @@ func checkParser(def testDefinition, t *testing.T, methodParam ...MethodParam) { ...@@ -75,7 +75,7 @@ func checkParser(def testDefinition, t *testing.T, methodParam ...MethodParam) {
} }
convResult, err := safeConvert(reflect.ValueOf(result), toType) convResult, err := safeConvert(reflect.ValueOf(result), toType)
if err != nil { if err != nil {
t.Errorf("Convertion error for %v. from value: %v, toType: %v, error: %v", def.strValue, result, toType, err) t.Errorf("Conversion error for %v. from value: %v, toType: %v, error: %v", def.strValue, result, toType, err)
return return
} }
if !reflect.DeepEqual(convResult.Interface(), def.expectedValue) { if !reflect.DeepEqual(convResult.Interface(), def.expectedValue) {
......
...@@ -36,7 +36,7 @@ func NewLog(out io.Writer) *Log { ...@@ -36,7 +36,7 @@ func NewLog(out io.Writer) *Log {
} }
func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) { func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error, args ...interface{}) {
sub := time.Now().Sub(t) / 1e5 sub := time.Since(t) / 1e5
elsp := float64(int(sub)) / 10.0 elsp := float64(int(sub)) / 10.0
flag := " OK" flag := " OK"
if err != nil { if err != nil {
......
...@@ -227,7 +227,7 @@ func parseComment(lines []*ast.Comment) (pc *parsedComment, err error) { ...@@ -227,7 +227,7 @@ func parseComment(lines []*ast.Comment) (pc *parsedComment, err error) {
} }
// direct copy from bee\g_docs.go // direct copy from bee\g_docs.go
// analisys params return []string // analysis params return []string
// @Param query form string true "The email for login" // @Param query form string true "The email for login"
// [query form string true "The email for login"] // [query form string true "The email for login"]
func getparams(str string) []string { func getparams(str string) []string {
......
...@@ -106,7 +106,7 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) { ...@@ -106,7 +106,7 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) {
if gcstats.NumGC > 0 { if gcstats.NumGC > 0 {
lastPause := gcstats.Pause[0] lastPause := gcstats.Pause[0]
elapsed := time.Now().Sub(startTime) elapsed := time.Since(startTime)
overhead := float64(gcstats.PauseTotal) / float64(elapsed) * 100 overhead := float64(gcstats.PauseTotal) / float64(elapsed) * 100
allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds() allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds()
...@@ -123,7 +123,7 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) { ...@@ -123,7 +123,7 @@ func printGC(memStats *runtime.MemStats, gcstats *debug.GCStats, w io.Writer) {
toS(gcstats.PauseQuantiles[99])) toS(gcstats.PauseQuantiles[99]))
} else { } else {
// while GC has disabled // while GC has disabled
elapsed := time.Now().Sub(startTime) elapsed := time.Since(startTime)
allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds() allocatedRate := float64(memStats.TotalAlloc) / elapsed.Seconds()
fmt.Fprintf(w, "Alloc:%s Sys:%s Alloc(Rate):%s/s\n", fmt.Fprintf(w, "Alloc:%s Sys:%s Alloc(Rate):%s/s\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment