From b664982be3ac920895f353ff27263b26a5adcdbc Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 15 Nov 2021 20:26:31 +0800 Subject: [PATCH] [feature] improve code gfile gcfg --- os/gcache/gcache.go | 3 ++- os/gcache/gcache_adapter.go | 3 ++- os/gcache/gcache_adapter_memory.go | 2 +- os/gcache/gcache_adapter_memory_data.go | 3 ++- os/gcache/gcache_adapter_memory_expire_sets.go | 3 ++- os/gcache/gcache_adapter_memory_item.go | 6 ++---- os/gcache/gcache_adapter_memory_lru.go | 4 ++-- os/gcache/gcache_cache.go | 3 ++- os/gcache/gcache_cache_must.go | 3 ++- os/gcache/gcache_z_example_cache_test.go | 3 ++- os/gcache/gcache_z_unit_basic_test.go | 6 +++--- os/gcfg/gcfg.go | 1 + os/gcfg/gcfg_adapter_file.go | 1 + os/gcfg/gcfg_adapter_file_content.go | 1 + os/gcfg/gcfg_adapter_file_path.go | 1 + os/gcfg/gcfg_z_unit_adapter_file_test.go | 3 ++- os/gcfg/gcfg_z_unit_basic_test.go | 7 +++---- os/gcfg/gcfg_z_unit_instance_test.go | 3 ++- os/gcmd/gcmd.go | 3 ++- os/gcmd/gcmd_parser.go | 10 ++++------ os/gcmd/gcmd_z_unit_default_test.go | 3 +-- os/gcmd/gcmd_z_unit_parser_test.go | 2 -- os/gcron/gcron.go | 2 +- os/gcron/gcron_entry.go | 4 ++-- os/gcron/gcron_schedule.go | 6 +++--- os/gcron/gcron_unit_1_test.go | 4 ++-- os/gcron/gcron_unit_2_test.go | 2 +- os/genv/genv.go | 5 +++-- os/genv/genv_test.go | 4 ++-- os/gfile/gfile.go | 2 +- os/gfile/gfile_cache.go | 3 ++- os/gfile/gfile_copy.go | 5 +++-- os/gfile/gfile_home.go | 5 +++-- os/gfile/gfile_scan.go | 7 ++++--- os/gfile/gfile_search.go | 4 ++-- os/gfile/gfile_source.go | 2 +- os/gfile/gfile_z_cache_test.go | 5 +++-- os/gfile/gfile_z_contents_test.go | 3 +-- os/gfile/gfile_z_copy_test.go | 3 ++- os/gfile/gfile_z_readline_test.go | 4 ++-- os/gfile/gfile_z_scan_test.go | 5 ++--- os/gfile/gfile_z_size_test.go | 2 +- os/gfile/gfile_z_test.go | 7 +++---- os/gfpool/gfpool.go | 7 ++++--- os/gfpool/gfpool_file.go | 11 ++++++----- os/gfpool/gfpool_z_unit_concurrent_test.go | 13 +++++++------ os/gfsnotify/gfsnotify.go | 8 ++++---- os/gfsnotify/gfsnotify_watcher.go | 4 ++-- os/gfsnotify/gfsnotify_watcher_loop.go | 1 + os/gfsnotify/gfsnotify_z_unit_test.go | 4 ++-- 50 files changed, 110 insertions(+), 96 deletions(-) diff --git a/os/gcache/gcache.go b/os/gcache/gcache.go index 8a1c6a3d3..02b8c15f5 100644 --- a/os/gcache/gcache.go +++ b/os/gcache/gcache.go @@ -11,8 +11,9 @@ package gcache import ( "context" - "github.com/gogf/gf/v2/container/gvar" "time" + + "github.com/gogf/gf/v2/container/gvar" ) // Default cache object. diff --git a/os/gcache/gcache_adapter.go b/os/gcache/gcache_adapter.go index c1bc7b452..0921e9101 100644 --- a/os/gcache/gcache_adapter.go +++ b/os/gcache/gcache_adapter.go @@ -8,8 +8,9 @@ package gcache import ( "context" - "github.com/gogf/gf/v2/container/gvar" "time" + + "github.com/gogf/gf/v2/container/gvar" ) // Adapter is the core adapter for cache features implements. diff --git a/os/gcache/gcache_adapter_memory.go b/os/gcache/gcache_adapter_memory.go index 767db7baf..5d1a40d29 100644 --- a/os/gcache/gcache_adapter_memory.go +++ b/os/gcache/gcache_adapter_memory.go @@ -8,13 +8,13 @@ package gcache import ( "context" - "github.com/gogf/gf/v2/container/gvar" "math" "time" "github.com/gogf/gf/v2/container/glist" "github.com/gogf/gf/v2/container/gset" "github.com/gogf/gf/v2/container/gtype" + "github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/os/gtimer" ) diff --git a/os/gcache/gcache_adapter_memory_data.go b/os/gcache/gcache_adapter_memory_data.go index ecacaf55c..86af48724 100644 --- a/os/gcache/gcache_adapter_memory_data.go +++ b/os/gcache/gcache_adapter_memory_data.go @@ -7,9 +7,10 @@ package gcache import ( - "github.com/gogf/gf/v2/os/gtime" "sync" "time" + + "github.com/gogf/gf/v2/os/gtime" ) type adapterMemoryData struct { diff --git a/os/gcache/gcache_adapter_memory_expire_sets.go b/os/gcache/gcache_adapter_memory_expire_sets.go index fae11606b..b49678c7c 100644 --- a/os/gcache/gcache_adapter_memory_expire_sets.go +++ b/os/gcache/gcache_adapter_memory_expire_sets.go @@ -7,8 +7,9 @@ package gcache import ( - "github.com/gogf/gf/v2/container/gset" "sync" + + "github.com/gogf/gf/v2/container/gset" ) type adapterMemoryExpireSets struct { diff --git a/os/gcache/gcache_adapter_memory_item.go b/os/gcache/gcache_adapter_memory_item.go index b8c4ee993..5a7862cae 100644 --- a/os/gcache/gcache_adapter_memory_item.go +++ b/os/gcache/gcache_adapter_memory_item.go @@ -14,8 +14,6 @@ import ( func (item *adapterMemoryItem) IsExpired() bool { // Note that it should use greater than or equal judgement here // imagining that the cache time is only 1 millisecond. - if item.e >= gtime.TimestampMilli() { - return false - } - return true + + return item.e < gtime.TimestampMilli() } diff --git a/os/gcache/gcache_adapter_memory_lru.go b/os/gcache/gcache_adapter_memory_lru.go index 6fe91f5ba..cf478996c 100644 --- a/os/gcache/gcache_adapter_memory_lru.go +++ b/os/gcache/gcache_adapter_memory_lru.go @@ -72,12 +72,12 @@ func (lru *adapterMemoryLru) Pop() interface{} { } // Print is used for test only. -//func (lru *adapterMemoryLru) Print() { +// func (lru *adapterMemoryLru) Print() { // for _, v := range lru.list.FrontAll() { // fmt.Printf("%v ", v) // } // fmt.Println() -//} +// } // SyncAndClear synchronizes the keys from `rawList` to `list` and `data` // using Least Recently Used algorithm. diff --git a/os/gcache/gcache_cache.go b/os/gcache/gcache_cache.go index 69221a5a9..b01e53870 100644 --- a/os/gcache/gcache_cache.go +++ b/os/gcache/gcache_cache.go @@ -8,9 +8,10 @@ package gcache import ( "context" + "time" + "github.com/gogf/gf/v2/os/gtimer" "github.com/gogf/gf/v2/util/gconv" - "time" ) // Cache struct. diff --git a/os/gcache/gcache_cache_must.go b/os/gcache/gcache_cache_must.go index 3b9eb0f32..ddb7946df 100644 --- a/os/gcache/gcache_cache_must.go +++ b/os/gcache/gcache_cache_must.go @@ -8,8 +8,9 @@ package gcache import ( "context" - "github.com/gogf/gf/v2/container/gvar" "time" + + "github.com/gogf/gf/v2/container/gvar" ) // MustGet acts like Get, but it panics if any error occurs. diff --git a/os/gcache/gcache_z_example_cache_test.go b/os/gcache/gcache_z_example_cache_test.go index 8b783c153..96b96e3f3 100644 --- a/os/gcache/gcache_z_example_cache_test.go +++ b/os/gcache/gcache_z_example_cache_test.go @@ -2,9 +2,10 @@ package gcache_test import ( "fmt" + "time" + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcache" - "time" ) func ExampleNew() { diff --git a/os/gcache/gcache_z_unit_basic_test.go b/os/gcache/gcache_z_unit_basic_test.go index 59ce23a0e..648b2e943 100644 --- a/os/gcache/gcache_z_unit_basic_test.go +++ b/os/gcache/gcache_z_unit_basic_test.go @@ -10,7 +10,6 @@ package gcache_test import ( "context" - "github.com/gogf/gf/v2/util/guid" "math" "testing" "time" @@ -20,6 +19,7 @@ import ( "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/grpool" "github.com/gogf/gf/v2/test/gtest" + "github.com/gogf/gf/v2/util/guid" ) var ( @@ -458,7 +458,7 @@ func TestCache_SetConcurrency(t *testing.T) { }() select { case <-time.After(2 * time.Second): - //t.Log("first part end") + // t.Log("first part end") } go func() { @@ -470,7 +470,7 @@ func TestCache_SetConcurrency(t *testing.T) { }() select { case <-time.After(2 * time.Second): - //t.Log("second part end") + // t.Log("second part end") } }) } diff --git a/os/gcfg/gcfg.go b/os/gcfg/gcfg.go index 81259c6b6..df038492a 100644 --- a/os/gcfg/gcfg.go +++ b/os/gcfg/gcfg.go @@ -10,6 +10,7 @@ package gcfg import ( "context" "fmt" + "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/internal/intlog" diff --git a/os/gcfg/gcfg_adapter_file.go b/os/gcfg/gcfg_adapter_file.go index 094a1a10b..f2a15f2ae 100644 --- a/os/gcfg/gcfg_adapter_file.go +++ b/os/gcfg/gcfg_adapter_file.go @@ -8,6 +8,7 @@ package gcfg import ( "context" + "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gvar" diff --git a/os/gcfg/gcfg_adapter_file_content.go b/os/gcfg/gcfg_adapter_file_content.go index 7719b868f..f72f7ff09 100644 --- a/os/gcfg/gcfg_adapter_file_content.go +++ b/os/gcfg/gcfg_adapter_file_content.go @@ -8,6 +8,7 @@ package gcfg import ( "context" + "github.com/gogf/gf/v2/internal/intlog" ) diff --git a/os/gcfg/gcfg_adapter_file_path.go b/os/gcfg/gcfg_adapter_file_path.go index 6eb4f6dc2..c826ed13c 100644 --- a/os/gcfg/gcfg_adapter_file_path.go +++ b/os/gcfg/gcfg_adapter_file_path.go @@ -10,6 +10,7 @@ import ( "bytes" "context" "fmt" + "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/internal/intlog" diff --git a/os/gcfg/gcfg_z_unit_adapter_file_test.go b/os/gcfg/gcfg_z_unit_adapter_file_test.go index e2f8a44d0..c0036a9f0 100644 --- a/os/gcfg/gcfg_z_unit_adapter_file_test.go +++ b/os/gcfg/gcfg_z_unit_adapter_file_test.go @@ -9,9 +9,10 @@ package gcfg_test import ( + "testing" + "github.com/gogf/gf/v2/os/gcfg" "github.com/gogf/gf/v2/test/gtest" - "testing" ) func TestAdapterFile_SetPath(t *testing.T) { diff --git a/os/gcfg/gcfg_z_unit_basic_test.go b/os/gcfg/gcfg_z_unit_basic_test.go index 118ab5bcd..50090421c 100644 --- a/os/gcfg/gcfg_z_unit_basic_test.go +++ b/os/gcfg/gcfg_z_unit_basic_test.go @@ -9,14 +9,13 @@ package gcfg_test import ( - "github.com/gogf/gf/v2/os/gcmd" - "github.com/gogf/gf/v2/os/genv" "testing" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/os/gcfg" + "github.com/gogf/gf/v2/os/gcmd" + "github.com/gogf/gf/v2/os/genv" "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" ) diff --git a/os/gcfg/gcfg_z_unit_instance_test.go b/os/gcfg/gcfg_z_unit_instance_test.go index 81a8c6389..2e7f0dc42 100644 --- a/os/gcfg/gcfg_z_unit_instance_test.go +++ b/os/gcfg/gcfg_z_unit_instance_test.go @@ -10,12 +10,13 @@ package gcfg import ( "context" + "testing" + "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/debug/gdebug" "github.com/gogf/gf/v2/os/genv" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/test/gtest" - "testing" ) var ( diff --git a/os/gcmd/gcmd.go b/os/gcmd/gcmd.go index b84575d48..5c80d0f5f 100644 --- a/os/gcmd/gcmd.go +++ b/os/gcmd/gcmd.go @@ -9,10 +9,11 @@ package gcmd import ( + "os" + "github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/internal/command" "github.com/gogf/gf/v2/internal/utils" - "os" ) var ( diff --git a/os/gcmd/gcmd_parser.go b/os/gcmd/gcmd_parser.go index 68d86fb74..9306be1b9 100644 --- a/os/gcmd/gcmd_parser.go +++ b/os/gcmd/gcmd_parser.go @@ -8,17 +8,15 @@ package gcmd import ( - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/internal/json" "os" "strings" - "github.com/gogf/gf/v2/text/gstr" - "github.com/gogf/gf/v2/container/gvar" - + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/text/gregex" + "github.com/gogf/gf/v2/text/gstr" ) // Parser for arguments. diff --git a/os/gcmd/gcmd_z_unit_default_test.go b/os/gcmd/gcmd_z_unit_default_test.go index b38978933..dc570e3c2 100644 --- a/os/gcmd/gcmd_z_unit_default_test.go +++ b/os/gcmd/gcmd_z_unit_default_test.go @@ -9,12 +9,11 @@ package gcmd_test import ( - "github.com/gogf/gf/v2/os/genv" "testing" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcmd" - + "github.com/gogf/gf/v2/os/genv" "github.com/gogf/gf/v2/test/gtest" ) diff --git a/os/gcmd/gcmd_z_unit_parser_test.go b/os/gcmd/gcmd_z_unit_parser_test.go index 445369d58..7e183542a 100644 --- a/os/gcmd/gcmd_z_unit_parser_test.go +++ b/os/gcmd/gcmd_z_unit_parser_test.go @@ -13,9 +13,7 @@ import ( "testing" "github.com/gogf/gf/v2/container/garray" - "github.com/gogf/gf/v2/os/gcmd" - "github.com/gogf/gf/v2/test/gtest" ) diff --git a/os/gcron/gcron.go b/os/gcron/gcron.go index ed53e0a8a..d1a7ad74e 100644 --- a/os/gcron/gcron.go +++ b/os/gcron/gcron.go @@ -9,9 +9,9 @@ package gcron import ( "context" - "github.com/gogf/gf/v2/os/glog" "time" + "github.com/gogf/gf/v2/os/glog" "github.com/gogf/gf/v2/os/gtimer" ) diff --git a/os/gcron/gcron_entry.go b/os/gcron/gcron_entry.go index 79e13754f..20e371dac 100644 --- a/os/gcron/gcron_entry.go +++ b/os/gcron/gcron_entry.go @@ -8,13 +8,13 @@ package gcron import ( "context" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" "reflect" "runtime" "time" "github.com/gogf/gf/v2/container/gtype" + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/os/gtimer" "github.com/gogf/gf/v2/util/gconv" ) diff --git a/os/gcron/gcron_schedule.go b/os/gcron/gcron_schedule.go index 5827071bd..71da89d95 100644 --- a/os/gcron/gcron_schedule.go +++ b/os/gcron/gcron_schedule.go @@ -7,13 +7,13 @@ package gcron import ( - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/os/gtime" "strconv" "strings" "time" + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/text/gregex" ) diff --git a/os/gcron/gcron_unit_1_test.go b/os/gcron/gcron_unit_1_test.go index 7d666d092..42e4d7552 100644 --- a/os/gcron/gcron_unit_1_test.go +++ b/os/gcron/gcron_unit_1_test.go @@ -8,11 +8,11 @@ package gcron_test import ( "context" - "github.com/gogf/gf/v2/frame/g" "testing" "time" "github.com/gogf/gf/v2/container/garray" + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcron" "github.com/gogf/gf/v2/test/gtest" ) @@ -52,7 +52,7 @@ func TestCron_Basic(t *testing.T) { gtest.C(t, func(t *gtest.T) { cron := gcron.New() cron.Add(ctx, "* * * * * *", func(ctx context.Context) {}, "add") - //fmt.Println("start", time.Now()) + // fmt.Println("start", time.Now()) cron.DelayAdd(ctx, time.Second, "* * * * * *", func(ctx context.Context) {}, "delay_add") t.Assert(cron.Size(), 1) time.Sleep(1200 * time.Millisecond) diff --git a/os/gcron/gcron_unit_2_test.go b/os/gcron/gcron_unit_2_test.go index ab05ef129..159197534 100644 --- a/os/gcron/gcron_unit_2_test.go +++ b/os/gcron/gcron_unit_2_test.go @@ -8,11 +8,11 @@ package gcron_test import ( "context" - "github.com/gogf/gf/v2/frame/g" "testing" "time" "github.com/gogf/gf/v2/container/garray" + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcron" "github.com/gogf/gf/v2/test/gtest" ) diff --git a/os/genv/genv.go b/os/genv/genv.go index d423d1e0b..0cc9e57c3 100644 --- a/os/genv/genv.go +++ b/os/genv/genv.go @@ -8,11 +8,12 @@ package genv import ( + "os" + "strings" + "github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/internal/utils" "github.com/gogf/gf/v2/os/gcmd" - "os" - "strings" ) // All returns a copy of strings representing the environment, diff --git a/os/genv/genv_test.go b/os/genv/genv_test.go index 7c1eef85f..ccdc9e5b7 100644 --- a/os/genv/genv_test.go +++ b/os/genv/genv_test.go @@ -7,11 +7,11 @@ package genv_test import ( - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/gcmd" "os" "testing" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/genv" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" diff --git a/os/gfile/gfile.go b/os/gfile/gfile.go index 3fc6e18b7..d635108c2 100644 --- a/os/gfile/gfile.go +++ b/os/gfile/gfile.go @@ -8,7 +8,6 @@ package gfile import ( - "github.com/gogf/gf/v2/text/gstr" "os" "os/exec" "path/filepath" @@ -16,6 +15,7 @@ import ( "time" "github.com/gogf/gf/v2/container/gtype" + "github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/util/gconv" ) diff --git a/os/gfile/gfile_cache.go b/os/gfile/gfile_cache.go index 340831b79..2ed7854d8 100644 --- a/os/gfile/gfile_cache.go +++ b/os/gfile/gfile_cache.go @@ -8,11 +8,12 @@ package gfile import ( "context" + "time" + "github.com/gogf/gf/v2/internal/intlog" "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gfsnotify" - "time" ) const ( diff --git a/os/gfile/gfile_copy.go b/os/gfile/gfile_copy.go index 9a241f937..eb94647f4 100644 --- a/os/gfile/gfile_copy.go +++ b/os/gfile/gfile_copy.go @@ -7,12 +7,13 @@ package gfile import ( - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" "io" "io/ioutil" "os" "path/filepath" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" ) // Copy file/directory from `src` to `dst`. diff --git a/os/gfile/gfile_home.go b/os/gfile/gfile_home.go index a6137b156..f75de43fe 100644 --- a/os/gfile/gfile_home.go +++ b/os/gfile/gfile_home.go @@ -8,13 +8,14 @@ package gfile import ( "bytes" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" "os" "os/exec" "os/user" "runtime" "strings" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" ) // Home returns absolute path of current user's home directory. diff --git a/os/gfile/gfile_scan.go b/os/gfile/gfile_scan.go index c3e244839..d5b02a370 100644 --- a/os/gfile/gfile_scan.go +++ b/os/gfile/gfile_scan.go @@ -7,12 +7,13 @@ package gfile import ( - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/text/gstr" "os" "path/filepath" "sort" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/text/gstr" ) const ( diff --git a/os/gfile/gfile_search.go b/os/gfile/gfile_search.go index a0ece5ed3..e344aa896 100644 --- a/os/gfile/gfile_search.go +++ b/os/gfile/gfile_search.go @@ -9,10 +9,10 @@ package gfile import ( "bytes" "fmt" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/container/garray" + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" ) // Search searches file by name `name` in following paths with priority: diff --git a/os/gfile/gfile_source.go b/os/gfile/gfile_source.go index 2c7c78a56..4f9726633 100644 --- a/os/gfile/gfile_source.go +++ b/os/gfile/gfile_source.go @@ -7,12 +7,12 @@ package gfile import ( - "github.com/gogf/gf/v2/text/gstr" "os" "runtime" "strings" "github.com/gogf/gf/v2/text/gregex" + "github.com/gogf/gf/v2/text/gstr" ) var ( diff --git a/os/gfile/gfile_z_cache_test.go b/os/gfile/gfile_z_cache_test.go index 22ddec7b6..77e0099e4 100644 --- a/os/gfile/gfile_z_cache_test.go +++ b/os/gfile/gfile_z_cache_test.go @@ -7,12 +7,13 @@ package gfile_test import ( - "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/v2/test/gtest" "io/ioutil" "os" "testing" "time" + + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/test/gtest" ) func Test_GetContentsWithCache(t *testing.T) { diff --git a/os/gfile/gfile_z_contents_test.go b/os/gfile/gfile_z_contents_test.go index 488cdfd22..e95f0c68f 100644 --- a/os/gfile/gfile_z_contents_test.go +++ b/os/gfile/gfile_z_contents_test.go @@ -13,10 +13,9 @@ import ( "strings" "testing" - "github.com/gogf/gf/v2/text/gstr" - "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/test/gtest" + "github.com/gogf/gf/v2/text/gstr" ) func createTestFile(filename, content string) error { diff --git a/os/gfile/gfile_z_copy_test.go b/os/gfile/gfile_z_copy_test.go index 3df4cd4b2..6a4ebdfdf 100644 --- a/os/gfile/gfile_z_copy_test.go +++ b/os/gfile/gfile_z_copy_test.go @@ -7,10 +7,11 @@ package gfile_test import ( + "testing" + "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" - "testing" ) func Test_Copy(t *testing.T) { diff --git a/os/gfile/gfile_z_readline_test.go b/os/gfile/gfile_z_readline_test.go index 82f1c273a..1cc860ebd 100644 --- a/os/gfile/gfile_z_readline_test.go +++ b/os/gfile/gfile_z_readline_test.go @@ -7,10 +7,10 @@ package gfile_test import ( - "github.com/gogf/gf/v2/debug/gdebug" - "github.com/gogf/gf/v2/errors/gerror" "testing" + "github.com/gogf/gf/v2/debug/gdebug" + "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/test/gtest" ) diff --git a/os/gfile/gfile_z_scan_test.go b/os/gfile/gfile_z_scan_test.go index e3da18f3f..c64ec62c0 100644 --- a/os/gfile/gfile_z_scan_test.go +++ b/os/gfile/gfile_z_scan_test.go @@ -7,12 +7,11 @@ package gfile_test import ( - "github.com/gogf/gf/v2/container/garray" - "github.com/gogf/gf/v2/debug/gdebug" "testing" + "github.com/gogf/gf/v2/container/garray" + "github.com/gogf/gf/v2/debug/gdebug" "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/v2/test/gtest" ) diff --git a/os/gfile/gfile_z_size_test.go b/os/gfile/gfile_z_size_test.go index 39d065ec1..f5f97c506 100644 --- a/os/gfile/gfile_z_size_test.go +++ b/os/gfile/gfile_z_size_test.go @@ -7,11 +7,11 @@ package gfile_test import ( - "github.com/gogf/gf/v2/util/gconv" "testing" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/test/gtest" + "github.com/gogf/gf/v2/util/gconv" ) func Test_Size(t *testing.T) { diff --git a/os/gfile/gfile_z_test.go b/os/gfile/gfile_z_test.go index fce200568..60d7bf7ba 100644 --- a/os/gfile/gfile_z_test.go +++ b/os/gfile/gfile_z_test.go @@ -12,11 +12,10 @@ import ( "strings" "testing" - "github.com/gogf/gf/v2/os/gtime" - "github.com/gogf/gf/v2/util/gconv" - "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" + "github.com/gogf/gf/v2/util/gconv" ) func Test_IsDir(t *testing.T) { @@ -399,7 +398,7 @@ func Test_Glob(t *testing.T) { testpath() + "/testfiles/t2.txt", } - //===============================构建测试文件 + // ===============================构建测试文件 createDir(dirpath) for _, v := range havelist1 { createTestFile(dirpath+"/"+v, "") diff --git a/os/gfpool/gfpool.go b/os/gfpool/gfpool.go index 98bf0e224..5eec01b27 100644 --- a/os/gfpool/gfpool.go +++ b/os/gfpool/gfpool.go @@ -8,14 +8,15 @@ package gfpool import ( + "os" + "time" + "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gpool" "github.com/gogf/gf/v2/container/gtype" - "os" - "time" ) -// File pointer pool. +// Pool pointer pool. type Pool struct { id *gtype.Int // Pool id, which is used to mark this pool whether recreated. pool *gpool.Pool // Underlying pool. diff --git a/os/gfpool/gfpool_file.go b/os/gfpool/gfpool_file.go index 3d318fd26..290615171 100644 --- a/os/gfpool/gfpool_file.go +++ b/os/gfpool/gfpool_file.go @@ -8,10 +8,11 @@ package gfpool import ( "fmt" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" "os" "time" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" ) // Open creates and returns a file item with given file path, flag and opening permission. @@ -25,10 +26,10 @@ func Open(path string, flag int, perm os.FileMode, ttl ...time.Duration) (file * // DO NOT search the path here wasting performance! // Leave following codes just for warning you. // - //path, err = gfile.Search(path) - //if err != nil { + // path, err = gfile.Search(path) + // if err != nil { // return nil, err - //} + // } pool := pools.GetOrSetFuncLock( fmt.Sprintf("%s&%d&%d&%d", path, flag, fpTTL, perm), func() interface{} { diff --git a/os/gfpool/gfpool_z_unit_concurrent_test.go b/os/gfpool/gfpool_z_unit_concurrent_test.go index 9c934b809..646293e09 100644 --- a/os/gfpool/gfpool_z_unit_concurrent_test.go +++ b/os/gfpool/gfpool_z_unit_concurrent_test.go @@ -7,13 +7,14 @@ package gfpool_test import ( + "os" + "testing" + "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfpool" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/text/gstr" - "os" - "testing" ) func Test_ConcurrentOS(t *testing.T) { @@ -97,7 +98,7 @@ func Test_ConcurrentOS(t *testing.T) { t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) // DATA RACE - //gtest.C(t, func(t *gtest.T) { + // gtest.C(t, func(t *gtest.T) { // path := gfile.TempDir(gtime.TimestampNanoStr()) // defer gfile.Remove(path) // f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) @@ -131,7 +132,7 @@ func Test_ConcurrentOS(t *testing.T) { // close(ch) // wg.Wait() // t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - //}) + // }) } func Test_ConcurrentGFPool(t *testing.T) { @@ -157,7 +158,7 @@ func Test_ConcurrentGFPool(t *testing.T) { t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) }) // DATA RACE - //gtest.C(t, func(t *gtest.T) { + // gtest.C(t, func(t *gtest.T) { // path := gfile.TempDir(gtime.TimestampNanoStr()) // defer gfile.Remove(path) // f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) @@ -191,5 +192,5 @@ func Test_ConcurrentGFPool(t *testing.T) { // close(ch) // wg.Wait() // t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) - //}) + // }) } diff --git a/os/gfsnotify/gfsnotify.go b/os/gfsnotify/gfsnotify.go index beadd0d52..12235ae61 100644 --- a/os/gfsnotify/gfsnotify.go +++ b/os/gfsnotify/gfsnotify.go @@ -9,10 +9,6 @@ package gfsnotify import ( "context" - "github.com/gogf/gf/v2/container/gset" - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" - "github.com/gogf/gf/v2/internal/intlog" "sync" "time" @@ -20,7 +16,11 @@ import ( "github.com/gogf/gf/v2/container/glist" "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gqueue" + "github.com/gogf/gf/v2/container/gset" "github.com/gogf/gf/v2/container/gtype" + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/internal/intlog" "github.com/gogf/gf/v2/os/gcache" ) diff --git a/os/gfsnotify/gfsnotify_watcher.go b/os/gfsnotify/gfsnotify_watcher.go index 92bf2cf00..87aee12b4 100644 --- a/os/gfsnotify/gfsnotify_watcher.go +++ b/os/gfsnotify/gfsnotify_watcher.go @@ -8,11 +8,11 @@ package gfsnotify import ( "context" + + "github.com/gogf/gf/v2/container/glist" "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/internal/intlog" - - "github.com/gogf/gf/v2/container/glist" ) // Add monitors `path` with callback function `callbackFunc` to the watcher. diff --git a/os/gfsnotify/gfsnotify_watcher_loop.go b/os/gfsnotify/gfsnotify_watcher_loop.go index bd41d3908..56c67e4be 100644 --- a/os/gfsnotify/gfsnotify_watcher_loop.go +++ b/os/gfsnotify/gfsnotify_watcher_loop.go @@ -8,6 +8,7 @@ package gfsnotify import ( "context" + "github.com/gogf/gf/v2/container/glist" "github.com/gogf/gf/v2/internal/intlog" ) diff --git a/os/gfsnotify/gfsnotify_z_unit_test.go b/os/gfsnotify/gfsnotify_z_unit_test.go index d8ec316c6..020e4fe09 100644 --- a/os/gfsnotify/gfsnotify_z_unit_test.go +++ b/os/gfsnotify/gfsnotify_z_unit_test.go @@ -7,10 +7,10 @@ package gfsnotify_test import ( - "github.com/gogf/gf/v2/container/garray" "testing" "time" + "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/gtype" "github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfsnotify" @@ -204,7 +204,7 @@ func TestWatcher_WatchFolderWithoutRecursively(t *testing.T) { t.AssertNil(err) _, err = gfsnotify.Add(dirPath, func(event *gfsnotify.Event) { - //fmt.Println(event.String()) + // fmt.Println(event.String()) array.Append(1) }, false) t.AssertNil(err)