diff --git a/debug/gdebug/gdebug_stack.go b/debug/gdebug/gdebug_stack.go index 522960803..67ec3e30e 100644 --- a/debug/gdebug/gdebug_stack.go +++ b/debug/gdebug/gdebug_stack.go @@ -9,7 +9,6 @@ package gdebug import ( "bytes" "fmt" - "path/filepath" "runtime" "strings" ) @@ -72,10 +71,6 @@ func StackWithFilters(filters []string, skip ...int) string { // Custom filtering. filtered = false for _, filter := range filters { - // Ignore test files. - if strings.HasSuffix(filepath.Base(file), "_test.go") { - break - } if filter != "" && strings.Contains(file, filter) { filtered = true break diff --git a/os/gcache/gcache.go b/os/gcache/gcache.go index fd4dc0f5a..80ef28aab 100644 --- a/os/gcache/gcache.go +++ b/os/gcache/gcache.go @@ -13,9 +13,6 @@ import ( "time" ) -// ValueFunc is the function for custom cache value producing. -type ValueFunc func() (value interface{}, err error) - // Default cache object. var defaultCache = New() @@ -61,7 +58,7 @@ func GetOrSet(key interface{}, value interface{}, duration time.Duration) (inter // GetOrSetFunc returns the value of , or sets with result of function // and returns its result if does not exist in the cache. The key-value pair expires // after . It does not expire if == 0. -func GetOrSetFunc(key interface{}, f ValueFunc, duration time.Duration) (interface{}, error) { +func GetOrSetFunc(key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error) { return defaultCache.GetOrSetFunc(key, f, duration) } @@ -70,7 +67,7 @@ func GetOrSetFunc(key interface{}, f ValueFunc, duration time.Duration) (interfa // after . It does not expire if == 0. // // Note that the function is executed within writing mutex lock. -func GetOrSetFuncLock(key interface{}, f ValueFunc, duration time.Duration) (interface{}, error) { +func GetOrSetFuncLock(key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error) { return defaultCache.GetOrSetFuncLock(key, f, duration) } diff --git a/os/gcache/gcache_adapter.go b/os/gcache/gcache_adapter.go index 28a022895..1dad55efe 100644 --- a/os/gcache/gcache_adapter.go +++ b/os/gcache/gcache_adapter.go @@ -55,7 +55,7 @@ type Adapter interface { // It does not expire if == 0. // It deletes the if < 0 or given is nil, but it does nothing // if is a function and the function result is nil. - GetOrSetFunc(key interface{}, f ValueFunc, duration time.Duration) (interface{}, error) + GetOrSetFunc(key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error) // GetOrSetFuncLock retrieves and returns the value of , or sets with result of // function and returns its result if does not exist in the cache. The key-value @@ -66,7 +66,7 @@ type Adapter interface { // // Note that the function should be executed within writing mutex lock for concurrent // safety purpose. - GetOrSetFuncLock(key interface{}, f ValueFunc, duration time.Duration) (interface{}, error) + GetOrSetFuncLock(key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error) // Contains returns true if exists in the cache, or else returns false. Contains(key interface{}) (bool, error) diff --git a/os/gcache/gcache_adapter_memory.go b/os/gcache/gcache_adapter_memory.go index 2eb7e9a5d..5dd532c61 100644 --- a/os/gcache/gcache_adapter_memory.go +++ b/os/gcache/gcache_adapter_memory.go @@ -252,7 +252,7 @@ func (c *adapterMemory) GetOrSet(key interface{}, value interface{}, duration ti // It does not expire if == 0. // It deletes the if < 0 or given is nil, but it does nothing // if is a function and the function result is nil. -func (c *adapterMemory) GetOrSetFunc(key interface{}, f ValueFunc, duration time.Duration) (interface{}, error) { +func (c *adapterMemory) GetOrSetFunc(key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error) { v, err := c.Get(key) if err != nil { return nil, err @@ -280,7 +280,7 @@ func (c *adapterMemory) GetOrSetFunc(key interface{}, f ValueFunc, duration time // // Note that the function should be executed within writing mutex lock for concurrent // safety purpose. -func (c *adapterMemory) GetOrSetFuncLock(key interface{}, f ValueFunc, duration time.Duration) (interface{}, error) { +func (c *adapterMemory) GetOrSetFuncLock(key interface{}, f func() (interface{}, error), duration time.Duration) (interface{}, error) { v, err := c.Get(key) if err != nil { return nil, err @@ -401,7 +401,7 @@ func (c *adapterMemory) doSetWithLockCheck(key interface{}, value interface{}, d if v, ok := c.data[key]; ok && !v.IsExpired() { return v.v, nil } - if f, ok := value.(ValueFunc); ok { + if f, ok := value.(func() (interface{}, error)); ok { v, err := f() if err != nil { return nil, err diff --git a/os/gfsnotify/gfsnotify_watcher_loop.go b/os/gfsnotify/gfsnotify_watcher_loop.go index 733b55220..c9ada4006 100644 --- a/os/gfsnotify/gfsnotify_watcher_loop.go +++ b/os/gfsnotify/gfsnotify_watcher_loop.go @@ -23,14 +23,14 @@ func (w *Watcher) startWatchLoop() { // Event listening. case ev := <-w.watcher.Events: // Filter the repeated event in custom duration. - w.cache.SetIfNotExist(ev.String(), func() interface{} { + w.cache.SetIfNotExist(ev.String(), func() (interface{}, error) { w.events.Push(&Event{ event: ev, Path: ev.Name, Op: Op(ev.Op), Watcher: w, }) - return struct{}{} + return struct{}{}, nil }, repeatEventFilterDuration) case err := <-w.watcher.Errors: