From 7a9b0847f96ae63d9e7ade7f4ca54f9c723004d9 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Mon, 3 Jan 2022 14:57:14 +0800 Subject: [PATCH] fix: fix some go line issue in go report card --- function/function.go | 6 +++--- function/function_util.go | 2 +- function/watcher.go | 3 +-- slice/slice.go | 14 +++++++------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/function/function.go b/function/function.go index 516b09b..437c34e 100644 --- a/function/function.go +++ b/function/function.go @@ -12,7 +12,7 @@ import ( // After creates a function that invokes func once it's called n or more times func After(n int, fn interface{}) func(args ...interface{}) []reflect.Value { // Catch programming error while constructing the closure - MustBeFunction(fn) + mustBeFunction(fn) return func(args ...interface{}) []reflect.Value { n-- if n < 1 { @@ -25,7 +25,7 @@ func After(n int, fn interface{}) func(args ...interface{}) []reflect.Value { // Before creates a function that invokes func once it's called less than n times func Before(n int, fn interface{}) func(args ...interface{}) []reflect.Value { // Catch programming error while constructing the closure - MustBeFunction(fn) + mustBeFunction(fn) var res []reflect.Value return func(args ...interface{}) []reflect.Value { if n > 0 { @@ -73,7 +73,7 @@ func Delay(delay time.Duration, fn interface{}, args ...interface{}) { // Schedule invoke function every duration time, util close the returned bool chan func Schedule(d time.Duration, fn interface{}, args ...interface{}) chan bool { // Catch programming error while constructing the closure - MustBeFunction(fn) + mustBeFunction(fn) quit := make(chan bool) go func() { for { diff --git a/function/function_util.go b/function/function_util.go index dcc08a4..b819d95 100644 --- a/function/function_util.go +++ b/function/function_util.go @@ -31,7 +31,7 @@ func functionValue(function interface{}) reflect.Value { return v } -func MustBeFunction(function interface{}) { +func mustBeFunction(function interface{}) { v := reflect.ValueOf(function) if v.Kind() != reflect.Func { panic(fmt.Sprintf("Invalid function type, value of type %T", function)) diff --git a/function/watcher.go b/function/watcher.go index 7fd6f92..a484acb 100644 --- a/function/watcher.go +++ b/function/watcher.go @@ -25,9 +25,8 @@ func (w *Watcher) Stop() { func (w *Watcher) GetElapsedTime() time.Duration { if w.excuting { return time.Duration(time.Now().UnixNano() - w.startTime) - } else { - return time.Duration(w.stopTime - w.startTime) } + return time.Duration(w.stopTime - w.startTime) } // Reset the watch timer. diff --git a/slice/slice.go b/slice/slice.go index 37d0a23..7911e9e 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -410,15 +410,15 @@ func Drop(slice interface{}, n int) interface{} { res.Index(i).Set(sv.Index(i + n)) } - return res.Interface() - } else { - res := reflect.MakeSlice(sv.Type(), svLen+n, svLen+n) - for i := 0; i < res.Len(); i++ { - res.Index(i).Set(sv.Index(i)) - } - return res.Interface() } + + res := reflect.MakeSlice(sv.Type(), svLen+n, svLen+n) + for i := 0; i < res.Len(); i++ { + res.Index(i).Set(sv.Index(i)) + } + + return res.Interface() } // InsertByIndex insert the element into slice at index.