From 1f2fcd39b15f6b62cffff80d8fa2c212ad21baf9 Mon Sep 17 00:00:00 2001 From: John Guo Date: Wed, 7 May 2025 19:11:44 +0800 Subject: [PATCH] refract(container/gtype): rename package `gtype` to `gatomic` (#4274) --- cmd/gf/internal/cmd/cmd_run.go | 4 +-- .../{gtype/gtype.go => gatomic/gatomic.go} | 4 +-- .../gtype_any.go => gatomic/gatomic_any.go} | 2 +- .../gatomic_any_test.go} | 16 +++++----- .../gtype_bool.go => gatomic/gatomic_bool.go} | 4 +-- .../gatomic_bool_test.go} | 26 ++++++++-------- .../gtype_byte.go => gatomic/gatomic_byte.go} | 4 +-- .../gatomic_byte_test.go} | 16 +++++----- .../gatomic_bytes.go} | 4 +-- .../gatomic_bytes_test.go} | 16 +++++----- .../gatomic_float32.go} | 4 +-- .../gatomic_float32_test.go} | 16 +++++----- .../gatomic_float64.go} | 4 +-- .../gatomic_float64_test.go} | 16 +++++----- .../gtype_int.go => gatomic/gatomic_int.go} | 4 +-- .../gatomic_int32.go} | 4 +-- .../gatomic_int32_test.go} | 16 +++++----- .../gatomic_int64.go} | 4 +-- .../gatomic_int64_test.go} | 16 +++++----- .../gatomic_int_test.go} | 16 +++++----- .../gatomic_interface.go} | 4 +-- .../gatomic_interface_test.go} | 16 +++++----- .../gatomic_string.go} | 4 +-- .../gatomic_string_test.go} | 14 ++++----- .../gtype_uint.go => gatomic/gatomic_uint.go} | 4 +-- .../gatomic_uint32.go} | 4 +-- .../gatomic_uint32_test.go} | 16 +++++----- .../gatomic_uint64.go} | 4 +-- .../gatomic_uint64_test.go} | 16 +++++----- .../gatomic_uint_test.go} | 16 +++++----- .../gatomic_z_bench_basic_test.go} | 24 +++++++-------- .../gatomic_z_bench_json_test.go} | 30 +++++++++---------- container/gpool/gpool.go | 6 ++-- container/gpool/gpool_z_unit_test.go | 4 +-- container/gqueue/gqueue.go | 6 ++-- container/gring/gring.go | 16 +++++----- container/gvar/gvar.go | 4 +-- container/gvar/gvar_basic.go | 4 +-- container/gvar/gvar_set.go | 4 +-- contrib/registry/file/file_discovery.go | 4 +-- contrib/registry/file/file_watcher.go | 4 +-- database/gdb/gdb.go | 6 ++-- database/gdb/gdb_core_transaction.go | 4 +-- internal/tracing/tracing.go | 4 +-- net/ghttp/ghttp.go | 8 ++--- net/ghttp/ghttp_server.go | 4 +-- net/ghttp/ghttp_server_admin_process.go | 6 ++-- net/ghttp/ghttp_server_router.go | 4 +-- net/ghttp/internal/graceful/graceful.go | 6 ++-- net/gsel/gsel_selector_least_connection.go | 6 ++-- os/gcache/gcache_adapter_memory.go | 6 ++-- os/gcron/gcron_cron.go | 10 +++---- os/gcron/gcron_entry.go | 10 +++---- os/gcron/gcron_schedule.go | 14 ++++----- os/gfile/gfile.go | 4 +-- os/gfpool/gfpool.go | 6 ++-- os/gfpool/gfpool_pool.go | 6 ++-- os/gfsnotify/gfsnotify.go | 4 +-- os/gfsnotify/gfsnotify_z_unit_test.go | 14 ++++----- os/glog/glog_logger_config.go | 6 ++-- os/gproc/gproc_comm_receive.go | 4 +-- os/grpool/grpool.go | 14 ++++----- os/gtimer/gtimer.go | 6 ++-- os/gtimer/gtimer_entry.go | 12 ++++---- os/gtimer/gtimer_queue.go | 6 ++-- os/gtimer/gtimer_timer.go | 16 +++++----- util/gconv/gconv_z_unit_issue_test.go | 26 ++++++++-------- util/guid/guid.go | 8 ++--- util/gutil/gutil_z_unit_dump_test.go | 4 +-- 69 files changed, 312 insertions(+), 312 deletions(-) rename container/{gtype/gtype.go => gatomic/gatomic.go} (78%) rename container/{gtype/gtype_any.go => gatomic/gatomic_any.go} (97%) rename container/{gtype/gtype_z_unit_any_test.go => gatomic/gatomic_any_test.go} (87%) rename container/{gtype/gtype_bool.go => gatomic/gatomic_bool.go} (97%) rename container/{gtype/gtype_z_unit_bool_test.go => gatomic/gatomic_bool_test.go} (88%) rename container/{gtype/gtype_byte.go => gatomic/gatomic_byte.go} (97%) rename container/{gtype/gtype_z_unit_byte_test.go => gatomic/gatomic_byte_test.go} (88%) rename container/{gtype/gtype_bytes.go => gatomic/gatomic_bytes.go} (97%) rename container/{gtype/gtype_z_unit_bytes_test.go => gatomic/gatomic_bytes_test.go} (85%) rename container/{gtype/gtype_float32.go => gatomic/gatomic_float32.go} (97%) rename container/{gtype/gtype_z_unit_float32_test.go => gatomic/gatomic_float32_test.go} (86%) rename container/{gtype/gtype_float64.go => gatomic/gatomic_float64.go} (97%) rename container/{gtype/gtype_z_unit_float64_test.go => gatomic/gatomic_float64_test.go} (86%) rename container/{gtype/gtype_int.go => gatomic/gatomic_int.go} (97%) rename container/{gtype/gtype_int32.go => gatomic/gatomic_int32.go} (97%) rename container/{gtype/gtype_z_unit_int32_test.go => gatomic/gatomic_int32_test.go} (88%) rename container/{gtype/gtype_int64.go => gatomic/gatomic_int64.go} (97%) rename container/{gtype/gtype_z_unit_int64_test.go => gatomic/gatomic_int64_test.go} (87%) rename container/{gtype/gtype_z_unit_int_test.go => gatomic/gatomic_int_test.go} (88%) rename container/{gtype/gtype_interface.go => gatomic/gatomic_interface.go} (96%) rename container/{gtype/gtype_z_unit_interface_test.go => gatomic/gatomic_interface_test.go} (87%) rename container/{gtype/gtype_string.go => gatomic/gatomic_string.go} (96%) rename container/{gtype/gtype_z_unit_string_test.go => gatomic/gatomic_string_test.go} (87%) rename container/{gtype/gtype_uint.go => gatomic/gatomic_uint.go} (97%) rename container/{gtype/gtype_uint32.go => gatomic/gatomic_uint32.go} (97%) rename container/{gtype/gtype_z_unit_uint32_test.go => gatomic/gatomic_uint32_test.go} (87%) rename container/{gtype/gtype_uint64.go => gatomic/gatomic_uint64.go} (97%) rename container/{gtype/gtype_z_unit_uint64_test.go => gatomic/gatomic_uint64_test.go} (87%) rename container/{gtype/gtype_z_unit_uint_test.go => gatomic/gatomic_uint_test.go} (88%) rename container/{gtype/gtype_z_bench_basic_test.go => gatomic/gatomic_z_bench_basic_test.go} (90%) rename container/{gtype/gtype_z_bench_json_test.go => gatomic/gatomic_z_bench_json_test.go} (75%) diff --git a/cmd/gf/internal/cmd/cmd_run.go b/cmd/gf/internal/cmd/cmd_run.go index 1a23bb43a..a4d911603 100644 --- a/cmd/gf/internal/cmd/cmd_run.go +++ b/cmd/gf/internal/cmd/cmd_run.go @@ -14,7 +14,7 @@ import ( "runtime" "strings" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/frame/g" "github.com/gogf/gf/v3/os/gfile" "github.com/gogf/gf/v3/os/gfsnotify" @@ -116,7 +116,7 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err Args: in.Args, WatchPaths: in.WatchPaths, } - dirty := gtype.NewBool() + dirty := gatomic.NewBool() var outputPath = app.genOutputPath() callbackFunc := func(event *gfsnotify.Event) { diff --git a/container/gtype/gtype.go b/container/gatomic/gatomic.go similarity index 78% rename from container/gtype/gtype.go rename to container/gatomic/gatomic.go index 2e6a11291..112e8ddd1 100644 --- a/container/gtype/gtype.go +++ b/container/gatomic/gatomic.go @@ -4,8 +4,8 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -// Package gtype provides high performance and concurrent-safe basic variable types. -package gtype +// Package gatomic provides high performance and concurrent-safe basic variable types. +package gatomic // New is alias of NewAny. // See NewAny, NewInterface. diff --git a/container/gtype/gtype_any.go b/container/gatomic/gatomic_any.go similarity index 97% rename from container/gtype/gtype_any.go rename to container/gatomic/gatomic_any.go index 6e9d2439c..1f6eb1320 100644 --- a/container/gtype/gtype_any.go +++ b/container/gatomic/gatomic_any.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic // Any is a struct for concurrent-safe operation for type any. type Any = Interface diff --git a/container/gtype/gtype_z_unit_any_test.go b/container/gatomic/gatomic_any_test.go similarity index 87% rename from container/gtype/gtype_z_unit_any_test.go rename to container/gatomic/gatomic_any_test.go index 4eee87477..a7eaa8e73 100644 --- a/container/gtype/gtype_z_unit_any_test.go +++ b/container/gatomic/gatomic_any_test.go @@ -4,12 +4,12 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -19,16 +19,16 @@ func Test_Any(t *testing.T) { gtest.C(t, func(t *gtest.T) { t1 := Temp{Name: "gf", Age: 18} t2 := Temp{Name: "gf", Age: 19} - i := gtype.New(t1) + i := gatomic.New(t1) iClone := i.Clone() t.AssertEQ(iClone.Set(t2), t1) t.AssertEQ(iClone.Val().(Temp), t2) // empty param test - i1 := gtype.New() + i1 := gatomic.New() t.AssertEQ(i1.Val(), nil) - i2 := gtype.New("gf") + i2 := gatomic.New("gf") t.AssertEQ(i2.String(), "gf") copyVal := i2.DeepCopy() i2.Set("goframe") @@ -42,14 +42,14 @@ func Test_Any(t *testing.T) { func Test_Any_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { s := "i love gf" - i := gtype.New(s) + i := gatomic.New(s) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.New() + i2 := gatomic.New() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), s) @@ -59,7 +59,7 @@ func Test_Any_JSON(t *testing.T) { func Test_Any_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Any + Var *gatomic.Any } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_bool.go b/container/gatomic/gatomic_bool.go similarity index 97% rename from container/gtype/gtype_bool.go rename to container/gatomic/gatomic_bool.go index 3000b6ab5..655155133 100644 --- a/container/gtype/gtype_bool.go +++ b/container/gatomic/gatomic_bool.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "bytes" @@ -78,7 +78,7 @@ func (v *Bool) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Bool) MarshalJSON() ([]byte, error) { +func (v *Bool) MarshalJSON() ([]byte, error) { if v.Val() { return bytesTrue, nil } diff --git a/container/gtype/gtype_z_unit_bool_test.go b/container/gatomic/gatomic_bool_test.go similarity index 88% rename from container/gtype/gtype_z_unit_bool_test.go rename to container/gatomic/gatomic_bool_test.go index a12a30efe..9a068ec22 100644 --- a/container/gtype/gtype_z_unit_bool_test.go +++ b/container/gatomic/gatomic_bool_test.go @@ -4,12 +4,12 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -17,12 +17,12 @@ import ( func Test_Bool(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewBool(true) + i := gatomic.NewBool(true) iClone := i.Clone() t.AssertEQ(iClone.Set(false), true) t.AssertEQ(iClone.Val(), false) - i1 := gtype.NewBool(false) + i1 := gatomic.NewBool(false) iClone1 := i1.Clone() t.AssertEQ(iClone1.Set(true), false) t.AssertEQ(iClone1.Val(), true) @@ -40,7 +40,7 @@ func Test_Bool(t *testing.T) { t.AssertNil(copyVal) // empty param test - i2 := gtype.NewBool() + i2 := gatomic.NewBool() t.AssertEQ(i2.Val(), false) }) } @@ -48,7 +48,7 @@ func Test_Bool(t *testing.T) { func Test_Bool_JSON(t *testing.T) { // Marshal gtest.C(t, func(t *gtest.T) { - i := gtype.NewBool(true) + i := gatomic.NewBool(true) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) @@ -56,7 +56,7 @@ func Test_Bool_JSON(t *testing.T) { t.Assert(b1, b2) }) gtest.C(t, func(t *gtest.T) { - i := gtype.NewBool(false) + i := gatomic.NewBool(false) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) @@ -66,7 +66,7 @@ func Test_Bool_JSON(t *testing.T) { // Unmarshal gtest.C(t, func(t *gtest.T) { var err error - i := gtype.NewBool() + i := gatomic.NewBool() err = json.UnmarshalUseNumber([]byte("true"), &i) t.AssertNil(err) t.Assert(i.Val(), true) @@ -82,27 +82,27 @@ func Test_Bool_JSON(t *testing.T) { }) gtest.C(t, func(t *gtest.T) { - i := gtype.NewBool(true) + i := gatomic.NewBool(true) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewBool() + i2 := gatomic.NewBool() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), i.Val()) }) gtest.C(t, func(t *gtest.T) { - i := gtype.NewBool(false) + i := gatomic.NewBool(false) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewBool() + i2 := gatomic.NewBool() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), i.Val()) @@ -112,7 +112,7 @@ func Test_Bool_JSON(t *testing.T) { func Test_Bool_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Bool + Var *gatomic.Bool } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_byte.go b/container/gatomic/gatomic_byte.go similarity index 97% rename from container/gtype/gtype_byte.go rename to container/gatomic/gatomic_byte.go index 4e2e0670e..0c9b4f521 100644 --- a/container/gtype/gtype_byte.go +++ b/container/gatomic/gatomic_byte.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Byte) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Byte) MarshalJSON() ([]byte, error) { +func (v *Byte) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatUint(uint64(v.Val()), 10)), nil } diff --git a/container/gtype/gtype_z_unit_byte_test.go b/container/gatomic/gatomic_byte_test.go similarity index 88% rename from container/gtype/gtype_z_unit_byte_test.go rename to container/gatomic/gatomic_byte_test.go index 4229e5d98..3846d0ebb 100644 --- a/container/gtype/gtype_z_unit_byte_test.go +++ b/container/gatomic/gatomic_byte_test.go @@ -4,13 +4,13 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -20,7 +20,7 @@ func Test_Byte(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 127 - i := gtype.NewByte(byte(0)) + i := gatomic.NewByte(byte(0)) iClone := i.Clone() t.AssertEQ(iClone.Set(byte(1)), byte(0)) t.AssertEQ(iClone.Val(), byte(1)) @@ -35,10 +35,10 @@ func Test_Byte(t *testing.T) { t.AssertEQ(byte(addTimes), i.Val()) // empty param test - i1 := gtype.NewByte() + i1 := gatomic.NewByte() t.AssertEQ(i1.Val(), byte(0)) - i2 := gtype.NewByte(byte(64)) + i2 := gatomic.NewByte(byte(64)) t.AssertEQ(i2.String(), "64") t.AssertEQ(i2.Cas(byte(63), byte(65)), false) t.AssertEQ(i2.Cas(byte(64), byte(65)), true) @@ -54,7 +54,7 @@ func Test_Byte(t *testing.T) { func Test_Byte_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewByte(49) + i := gatomic.NewByte(49) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) @@ -64,7 +64,7 @@ func Test_Byte_JSON(t *testing.T) { // Unmarshal gtest.C(t, func(t *gtest.T) { var err error - i := gtype.NewByte() + i := gatomic.NewByte() err = json.UnmarshalUseNumber([]byte("49"), &i) t.AssertNil(err) t.Assert(i.Val(), "49") @@ -74,7 +74,7 @@ func Test_Byte_JSON(t *testing.T) { func Test_Byte_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Byte + Var *gatomic.Byte } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_bytes.go b/container/gatomic/gatomic_bytes.go similarity index 97% rename from container/gtype/gtype_bytes.go rename to container/gatomic/gatomic_bytes.go index 4cccabd51..769c16391 100644 --- a/container/gtype/gtype_bytes.go +++ b/container/gatomic/gatomic_bytes.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "bytes" @@ -57,7 +57,7 @@ func (v *Bytes) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Bytes) MarshalJSON() ([]byte, error) { +func (v *Bytes) MarshalJSON() ([]byte, error) { val := v.Val() dst := make([]byte, base64.StdEncoding.EncodedLen(len(val))) base64.StdEncoding.Encode(dst, val) diff --git a/container/gtype/gtype_z_unit_bytes_test.go b/container/gatomic/gatomic_bytes_test.go similarity index 85% rename from container/gtype/gtype_z_unit_bytes_test.go rename to container/gatomic/gatomic_bytes_test.go index 38c18161c..925ebde65 100644 --- a/container/gtype/gtype_z_unit_bytes_test.go +++ b/container/gatomic/gatomic_bytes_test.go @@ -4,12 +4,12 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -17,16 +17,16 @@ import ( func Test_Bytes(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewBytes([]byte("abc")) + i := gatomic.NewBytes([]byte("abc")) iClone := i.Clone() t.AssertEQ(iClone.Set([]byte("123")), []byte("abc")) t.AssertEQ(iClone.Val(), []byte("123")) // empty param test - i1 := gtype.NewBytes() + i1 := gatomic.NewBytes() t.AssertEQ(i1.Val(), nil) - i2 := gtype.NewBytes([]byte("abc")) + i2 := gatomic.NewBytes([]byte("abc")) t.Assert(i2.String(), "abc") copyVal := i2.DeepCopy() @@ -41,14 +41,14 @@ func Test_Bytes(t *testing.T) { func Test_Bytes_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { b := []byte("i love gf") - i := gtype.NewBytes(b) + i := gatomic.NewBytes(b) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewBytes() + i2 := gatomic.NewBytes() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), b) @@ -58,7 +58,7 @@ func Test_Bytes_JSON(t *testing.T) { func Test_Bytes_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Bytes + Var *gatomic.Bytes } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_float32.go b/container/gatomic/gatomic_float32.go similarity index 97% rename from container/gtype/gtype_float32.go rename to container/gatomic/gatomic_float32.go index 9267c8234..9486d745f 100644 --- a/container/gtype/gtype_float32.go +++ b/container/gatomic/gatomic_float32.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "math" @@ -72,7 +72,7 @@ func (v *Float32) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Float32) MarshalJSON() ([]byte, error) { +func (v *Float32) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatFloat(float64(v.Val()), 'g', -1, 32)), nil } diff --git a/container/gtype/gtype_z_unit_float32_test.go b/container/gatomic/gatomic_float32_test.go similarity index 86% rename from container/gtype/gtype_z_unit_float32_test.go rename to container/gatomic/gatomic_float32_test.go index 8c1a9edae..329e14946 100644 --- a/container/gtype/gtype_z_unit_float32_test.go +++ b/container/gatomic/gatomic_float32_test.go @@ -4,13 +4,13 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "math" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -18,16 +18,16 @@ import ( func Test_Float32(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewFloat32(0) + i := gatomic.NewFloat32(0) iClone := i.Clone() t.AssertEQ(iClone.Set(0.1), float32(0)) t.AssertEQ(iClone.Val(), float32(0.1)) // empty param test - i1 := gtype.NewFloat32() + i1 := gatomic.NewFloat32() t.AssertEQ(i1.Val(), float32(0)) - i2 := gtype.NewFloat32(1.23) + i2 := gatomic.NewFloat32(1.23) t.AssertEQ(i2.Add(3.21), float32(4.44)) t.AssertEQ(i2.Cas(4.45, 5.55), false) t.AssertEQ(i2.Cas(4.44, 5.55), true) @@ -45,7 +45,7 @@ func Test_Float32(t *testing.T) { func Test_Float32_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { v := float32(math.MaxFloat32) - i := gtype.NewFloat32(v) + i := gatomic.NewFloat32(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) @@ -53,7 +53,7 @@ func Test_Float32_JSON(t *testing.T) { t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewFloat32() + i2 := gatomic.NewFloat32() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), v) @@ -63,7 +63,7 @@ func Test_Float32_JSON(t *testing.T) { func Test_Float32_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Float32 + Var *gatomic.Float32 } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_float64.go b/container/gatomic/gatomic_float64.go similarity index 97% rename from container/gtype/gtype_float64.go rename to container/gatomic/gatomic_float64.go index b3caacd9e..6da2124f1 100644 --- a/container/gtype/gtype_float64.go +++ b/container/gatomic/gatomic_float64.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "math" @@ -72,7 +72,7 @@ func (v *Float64) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Float64) MarshalJSON() ([]byte, error) { +func (v *Float64) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatFloat(v.Val(), 'g', -1, 64)), nil } diff --git a/container/gtype/gtype_z_unit_float64_test.go b/container/gatomic/gatomic_float64_test.go similarity index 86% rename from container/gtype/gtype_z_unit_float64_test.go rename to container/gatomic/gatomic_float64_test.go index 215b80d32..b9375222c 100644 --- a/container/gtype/gtype_z_unit_float64_test.go +++ b/container/gatomic/gatomic_float64_test.go @@ -4,13 +4,13 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "math" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -18,15 +18,15 @@ import ( func Test_Float64(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewFloat64(0) + i := gatomic.NewFloat64(0) iClone := i.Clone() t.AssertEQ(iClone.Set(0.1), float64(0)) t.AssertEQ(iClone.Val(), float64(0.1)) // empty param test - i1 := gtype.NewFloat64() + i1 := gatomic.NewFloat64() t.AssertEQ(i1.Val(), float64(0)) - i2 := gtype.NewFloat64(1.1) + i2 := gatomic.NewFloat64(1.1) t.AssertEQ(i2.Add(3.3), 4.4) t.AssertEQ(i2.Cas(4.5, 5.5), false) t.AssertEQ(i2.Cas(4.4, 5.5), true) @@ -44,14 +44,14 @@ func Test_Float64(t *testing.T) { func Test_Float64_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { v := math.MaxFloat64 - i := gtype.NewFloat64(v) + i := gatomic.NewFloat64(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewFloat64() + i2 := gatomic.NewFloat64() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), v) @@ -61,7 +61,7 @@ func Test_Float64_JSON(t *testing.T) { func Test_Float64_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Float64 + Var *gatomic.Float64 } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_int.go b/container/gatomic/gatomic_int.go similarity index 97% rename from container/gtype/gtype_int.go rename to container/gatomic/gatomic_int.go index f973d0be0..52ea2d0e8 100644 --- a/container/gtype/gtype_int.go +++ b/container/gatomic/gatomic_int.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Int) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Int) MarshalJSON() ([]byte, error) { +func (v *Int) MarshalJSON() ([]byte, error) { return []byte(strconv.Itoa(v.Val())), nil } diff --git a/container/gtype/gtype_int32.go b/container/gatomic/gatomic_int32.go similarity index 97% rename from container/gtype/gtype_int32.go rename to container/gatomic/gatomic_int32.go index 465eed233..7019b1f24 100644 --- a/container/gtype/gtype_int32.go +++ b/container/gatomic/gatomic_int32.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Int32) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Int32) MarshalJSON() ([]byte, error) { +func (v *Int32) MarshalJSON() ([]byte, error) { return []byte(strconv.Itoa(int(v.Val()))), nil } diff --git a/container/gtype/gtype_z_unit_int32_test.go b/container/gatomic/gatomic_int32_test.go similarity index 88% rename from container/gtype/gtype_z_unit_int32_test.go rename to container/gatomic/gatomic_int32_test.go index 9879cfbdc..87ad91b0b 100644 --- a/container/gtype/gtype_z_unit_int32_test.go +++ b/container/gatomic/gatomic_int32_test.go @@ -4,14 +4,14 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "math" "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -21,7 +21,7 @@ func Test_Int32(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 - i := gtype.NewInt32(0) + i := gatomic.NewInt32(0) iClone := i.Clone() t.AssertEQ(iClone.Set(1), int32(0)) t.AssertEQ(iClone.Val(), int32(1)) @@ -36,10 +36,10 @@ func Test_Int32(t *testing.T) { t.AssertEQ(int32(addTimes), i.Val()) // empty param test - i1 := gtype.NewInt32() + i1 := gatomic.NewInt32() t.AssertEQ(i1.Val(), int32(0)) - i2 := gtype.NewInt32(11) + i2 := gatomic.NewInt32(11) t.AssertEQ(i2.Add(1), int32(12)) t.AssertEQ(i2.Cas(11, 13), false) t.AssertEQ(i2.Cas(12, 13), true) @@ -57,14 +57,14 @@ func Test_Int32(t *testing.T) { func Test_Int32_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { v := int32(math.MaxInt32) - i := gtype.NewInt32(v) + i := gatomic.NewInt32(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewInt32() + i2 := gatomic.NewInt32() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), v) @@ -74,7 +74,7 @@ func Test_Int32_JSON(t *testing.T) { func Test_Int32_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Int32 + Var *gatomic.Int32 } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_int64.go b/container/gatomic/gatomic_int64.go similarity index 97% rename from container/gtype/gtype_int64.go rename to container/gatomic/gatomic_int64.go index f11fe3ebf..97d0f4207 100644 --- a/container/gtype/gtype_int64.go +++ b/container/gatomic/gatomic_int64.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Int64) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Int64) MarshalJSON() ([]byte, error) { +func (v *Int64) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatInt(v.Val(), 10)), nil } diff --git a/container/gtype/gtype_z_unit_int64_test.go b/container/gatomic/gatomic_int64_test.go similarity index 87% rename from container/gtype/gtype_z_unit_int64_test.go rename to container/gatomic/gatomic_int64_test.go index 150adbab3..75511eb57 100644 --- a/container/gtype/gtype_z_unit_int64_test.go +++ b/container/gatomic/gatomic_int64_test.go @@ -4,14 +4,14 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "math" "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -21,7 +21,7 @@ func Test_Int64(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 - i := gtype.NewInt64(0) + i := gatomic.NewInt64(0) iClone := i.Clone() t.AssertEQ(iClone.Set(1), int64(0)) t.AssertEQ(iClone.Val(), int64(1)) @@ -36,10 +36,10 @@ func Test_Int64(t *testing.T) { t.AssertEQ(int64(addTimes), i.Val()) // empty param test - i1 := gtype.NewInt64() + i1 := gatomic.NewInt64() t.AssertEQ(i1.Val(), int64(0)) - i2 := gtype.NewInt64(11) + i2 := gatomic.NewInt64(11) t.AssertEQ(i2.Add(1), int64(12)) t.AssertEQ(i2.Cas(11, 13), false) t.AssertEQ(i2.Cas(12, 13), true) @@ -56,14 +56,14 @@ func Test_Int64(t *testing.T) { func Test_Int64_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewInt64(math.MaxInt64) + i := gatomic.NewInt64(math.MaxInt64) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewInt64() + i2 := gatomic.NewInt64() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), i) @@ -73,7 +73,7 @@ func Test_Int64_JSON(t *testing.T) { func Test_Int64_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Int64 + Var *gatomic.Int64 } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_z_unit_int_test.go b/container/gatomic/gatomic_int_test.go similarity index 88% rename from container/gtype/gtype_z_unit_int_test.go rename to container/gatomic/gatomic_int_test.go index b071739fa..217a740f6 100644 --- a/container/gtype/gtype_z_unit_int_test.go +++ b/container/gatomic/gatomic_int_test.go @@ -4,13 +4,13 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -20,7 +20,7 @@ func Test_Int(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 - i := gtype.NewInt(0) + i := gatomic.NewInt(0) iClone := i.Clone() t.AssertEQ(iClone.Set(1), 0) t.AssertEQ(iClone.Val(), 1) @@ -35,10 +35,10 @@ func Test_Int(t *testing.T) { t.AssertEQ(addTimes, i.Val()) // empty param test - i1 := gtype.NewInt() + i1 := gatomic.NewInt() t.AssertEQ(i1.Val(), 0) - i2 := gtype.NewInt(11) + i2 := gatomic.NewInt(11) t.AssertEQ(i2.Add(1), 12) t.AssertEQ(i2.Cas(11, 13), false) t.AssertEQ(i2.Cas(12, 13), true) @@ -56,14 +56,14 @@ func Test_Int(t *testing.T) { func Test_Int_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { v := 666 - i := gtype.NewInt(v) + i := gatomic.NewInt(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewInt() + i2 := gatomic.NewInt() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), v) @@ -73,7 +73,7 @@ func Test_Int_JSON(t *testing.T) { func Test_Int_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Int + Var *gatomic.Int } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_interface.go b/container/gatomic/gatomic_interface.go similarity index 96% rename from container/gtype/gtype_interface.go rename to container/gatomic/gatomic_interface.go index 91a27a65f..3ea09438a 100644 --- a/container/gtype/gtype_interface.go +++ b/container/gatomic/gatomic_interface.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "sync/atomic" @@ -53,7 +53,7 @@ func (v *Interface) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Interface) MarshalJSON() ([]byte, error) { +func (v *Interface) MarshalJSON() ([]byte, error) { return json.Marshal(v.Val()) } diff --git a/container/gtype/gtype_z_unit_interface_test.go b/container/gatomic/gatomic_interface_test.go similarity index 87% rename from container/gtype/gtype_z_unit_interface_test.go rename to container/gatomic/gatomic_interface_test.go index efd664a6d..32567efc4 100644 --- a/container/gtype/gtype_z_unit_interface_test.go +++ b/container/gatomic/gatomic_interface_test.go @@ -4,12 +4,12 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -19,16 +19,16 @@ func Test_Interface(t *testing.T) { gtest.C(t, func(t *gtest.T) { t1 := Temp{Name: "gf", Age: 18} t2 := Temp{Name: "gf", Age: 19} - i := gtype.New(t1) + i := gatomic.New(t1) iClone := i.Clone() t.AssertEQ(iClone.Set(t2), t1) t.AssertEQ(iClone.Val().(Temp), t2) // empty param test - i1 := gtype.New() + i1 := gatomic.New() t.AssertEQ(i1.Val(), nil) - i2 := gtype.New("gf") + i2 := gatomic.New("gf") t.AssertEQ(i2.String(), "gf") copyVal := i2.DeepCopy() i2.Set("goframe") @@ -42,14 +42,14 @@ func Test_Interface(t *testing.T) { func Test_Interface_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { s := "i love gf" - i := gtype.New(s) + i := gatomic.New(s) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.New() + i2 := gatomic.New() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), s) @@ -59,7 +59,7 @@ func Test_Interface_JSON(t *testing.T) { func Test_Interface_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Interface + Var *gatomic.Interface } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_string.go b/container/gatomic/gatomic_string.go similarity index 96% rename from container/gtype/gtype_string.go rename to container/gatomic/gatomic_string.go index 0c253a2e6..cf08d5bfc 100644 --- a/container/gtype/gtype_string.go +++ b/container/gatomic/gatomic_string.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "bytes" @@ -55,7 +55,7 @@ func (v *String) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v String) MarshalJSON() ([]byte, error) { +func (v *String) MarshalJSON() ([]byte, error) { return []byte(`"` + v.Val() + `"`), nil } diff --git a/container/gtype/gtype_z_unit_string_test.go b/container/gatomic/gatomic_string_test.go similarity index 87% rename from container/gtype/gtype_z_unit_string_test.go rename to container/gatomic/gatomic_string_test.go index 120a4fa4d..8741a5016 100644 --- a/container/gtype/gtype_z_unit_string_test.go +++ b/container/gatomic/gatomic_string_test.go @@ -4,12 +4,12 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -17,7 +17,7 @@ import ( func Test_String(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewString("abc") + i := gatomic.NewString("abc") iClone := i.Clone() t.AssertEQ(iClone.Set("123"), "abc") t.AssertEQ(iClone.Val(), "123") @@ -30,7 +30,7 @@ func Test_String(t *testing.T) { copyVal = iClone.DeepCopy() t.AssertNil(copyVal) // empty param test - i1 := gtype.NewString() + i1 := gatomic.NewString() t.AssertEQ(i1.Val(), "") }) } @@ -38,14 +38,14 @@ func Test_String(t *testing.T) { func Test_String_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { s := "i love gf" - i1 := gtype.NewString(s) + i1 := gatomic.NewString(s) b1, err1 := json.Marshal(i1) b2, err2 := json.Marshal(i1.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewString() + i2 := gatomic.NewString() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), s) @@ -55,7 +55,7 @@ func Test_String_JSON(t *testing.T) { func Test_String_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.String + Var *gatomic.String } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_uint.go b/container/gatomic/gatomic_uint.go similarity index 97% rename from container/gtype/gtype_uint.go rename to container/gatomic/gatomic_uint.go index 2b8404647..173c24943 100644 --- a/container/gtype/gtype_uint.go +++ b/container/gatomic/gatomic_uint.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Uint) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Uint) MarshalJSON() ([]byte, error) { +func (v *Uint) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatUint(uint64(v.Val()), 10)), nil } diff --git a/container/gtype/gtype_uint32.go b/container/gatomic/gatomic_uint32.go similarity index 97% rename from container/gtype/gtype_uint32.go rename to container/gatomic/gatomic_uint32.go index 6709a2b77..8b05c2a1e 100644 --- a/container/gtype/gtype_uint32.go +++ b/container/gatomic/gatomic_uint32.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Uint32) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Uint32) MarshalJSON() ([]byte, error) { +func (v *Uint32) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatUint(uint64(v.Val()), 10)), nil } diff --git a/container/gtype/gtype_z_unit_uint32_test.go b/container/gatomic/gatomic_uint32_test.go similarity index 87% rename from container/gtype/gtype_z_unit_uint32_test.go rename to container/gatomic/gatomic_uint32_test.go index d1ef70cfe..d822f8b18 100644 --- a/container/gtype/gtype_z_unit_uint32_test.go +++ b/container/gatomic/gatomic_uint32_test.go @@ -4,14 +4,14 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "math" "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -21,7 +21,7 @@ func Test_Uint32(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 - i := gtype.NewUint32(0) + i := gatomic.NewUint32(0) iClone := i.Clone() t.AssertEQ(iClone.Set(1), uint32(0)) t.AssertEQ(iClone.Val(), uint32(1)) @@ -36,10 +36,10 @@ func Test_Uint32(t *testing.T) { t.AssertEQ(uint32(addTimes), i.Val()) // empty param test - i1 := gtype.NewUint32() + i1 := gatomic.NewUint32() t.AssertEQ(i1.Val(), uint32(0)) - i2 := gtype.NewUint32(11) + i2 := gatomic.NewUint32(11) t.AssertEQ(i2.Add(1), uint32(12)) t.AssertEQ(i2.Cas(11, 13), false) t.AssertEQ(i2.Cas(12, 13), true) @@ -56,14 +56,14 @@ func Test_Uint32(t *testing.T) { func Test_Uint32_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewUint32(math.MaxUint32) + i := gatomic.NewUint32(math.MaxUint32) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewUint32() + i2 := gatomic.NewUint32() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), i) @@ -73,7 +73,7 @@ func Test_Uint32_JSON(t *testing.T) { func Test_Uint32_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Uint32 + Var *gatomic.Uint32 } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_uint64.go b/container/gatomic/gatomic_uint64.go similarity index 97% rename from container/gtype/gtype_uint64.go rename to container/gatomic/gatomic_uint64.go index 19e314bb1..9899b435e 100644 --- a/container/gtype/gtype_uint64.go +++ b/container/gatomic/gatomic_uint64.go @@ -4,7 +4,7 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype +package gatomic import ( "strconv" @@ -60,7 +60,7 @@ func (v *Uint64) String() string { } // MarshalJSON implements the interface MarshalJSON for json.Marshal. -func (v Uint64) MarshalJSON() ([]byte, error) { +func (v *Uint64) MarshalJSON() ([]byte, error) { return []byte(strconv.FormatUint(v.Val(), 10)), nil } diff --git a/container/gtype/gtype_z_unit_uint64_test.go b/container/gatomic/gatomic_uint64_test.go similarity index 87% rename from container/gtype/gtype_z_unit_uint64_test.go rename to container/gatomic/gatomic_uint64_test.go index 1f7016ce0..193119f25 100644 --- a/container/gtype/gtype_z_unit_uint64_test.go +++ b/container/gatomic/gatomic_uint64_test.go @@ -4,14 +4,14 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "math" "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -26,7 +26,7 @@ func Test_Uint64(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 - i := gtype.NewUint64(0) + i := gatomic.NewUint64(0) iClone := i.Clone() t.AssertEQ(iClone.Set(1), uint64(0)) t.AssertEQ(iClone.Val(), uint64(1)) @@ -41,10 +41,10 @@ func Test_Uint64(t *testing.T) { t.AssertEQ(uint64(addTimes), i.Val()) // empty param test - i1 := gtype.NewUint64() + i1 := gatomic.NewUint64() t.AssertEQ(i1.Val(), uint64(0)) - i2 := gtype.NewUint64(11) + i2 := gatomic.NewUint64(11) t.AssertEQ(i2.Add(1), uint64(12)) t.AssertEQ(i2.Cas(11, 13), false) t.AssertEQ(i2.Cas(12, 13), true) @@ -61,14 +61,14 @@ func Test_Uint64(t *testing.T) { func Test_Uint64_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewUint64(math.MaxUint64) + i := gatomic.NewUint64(math.MaxUint64) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewUint64() + i2 := gatomic.NewUint64() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), i) @@ -78,7 +78,7 @@ func Test_Uint64_JSON(t *testing.T) { func Test_Uint64_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Uint64 + Var *gatomic.Uint64 } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_z_unit_uint_test.go b/container/gatomic/gatomic_uint_test.go similarity index 88% rename from container/gtype/gtype_z_unit_uint_test.go rename to container/gatomic/gatomic_uint_test.go index 6069b3e81..016f73ec2 100644 --- a/container/gtype/gtype_z_unit_uint_test.go +++ b/container/gatomic/gatomic_uint_test.go @@ -4,13 +4,13 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -package gtype_test +package gatomic_test import ( "sync" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/test/gtest" "github.com/gogf/gf/v3/util/gconv" @@ -20,7 +20,7 @@ func Test_Uint(t *testing.T) { gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 - i := gtype.NewUint(0) + i := gatomic.NewUint(0) iClone := i.Clone() t.AssertEQ(iClone.Set(1), uint(0)) t.AssertEQ(iClone.Val(), uint(1)) @@ -35,10 +35,10 @@ func Test_Uint(t *testing.T) { t.AssertEQ(uint(addTimes), i.Val()) // empty param test - i1 := gtype.NewUint() + i1 := gatomic.NewUint() t.AssertEQ(i1.Val(), uint(0)) - i2 := gtype.NewUint(11) + i2 := gatomic.NewUint(11) t.AssertEQ(i2.Add(1), uint(12)) t.AssertEQ(i2.Cas(11, 13), false) t.AssertEQ(i2.Cas(12, 13), true) @@ -55,14 +55,14 @@ func Test_Uint(t *testing.T) { func Test_Uint_JSON(t *testing.T) { gtest.C(t, func(t *gtest.T) { - i := gtype.NewUint(666) + i := gatomic.NewUint(666) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) t.Assert(err1, nil) t.Assert(err2, nil) t.Assert(b1, b2) - i2 := gtype.NewUint() + i2 := gatomic.NewUint() err := json.UnmarshalUseNumber(b2, &i2) t.AssertNil(err) t.Assert(i2.Val(), i) @@ -72,7 +72,7 @@ func Test_Uint_JSON(t *testing.T) { func Test_Uint_UnmarshalValue(t *testing.T) { type V struct { Name string - Var *gtype.Uint + Var *gatomic.Uint } gtest.C(t, func(t *gtest.T) { var v *V diff --git a/container/gtype/gtype_z_bench_basic_test.go b/container/gatomic/gatomic_z_bench_basic_test.go similarity index 90% rename from container/gtype/gtype_z_bench_basic_test.go rename to container/gatomic/gatomic_z_bench_basic_test.go index c9884fa92..f56ffacc3 100644 --- a/container/gtype/gtype_z_bench_basic_test.go +++ b/container/gatomic/gatomic_z_bench_basic_test.go @@ -6,28 +6,28 @@ // go test *.go -bench=".*" -benchmem -package gtype_test +package gatomic_test import ( "strconv" "sync/atomic" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/encoding/gbinary" ) var ( - it = gtype.NewInt() - it32 = gtype.NewInt32() - it64 = gtype.NewInt64() - uit = gtype.NewUint() - uit32 = gtype.NewUint32() - uit64 = gtype.NewUint64() - bl = gtype.NewBool() - vbytes = gtype.NewBytes() - str = gtype.NewString() - inf = gtype.NewInterface() + it = gatomic.NewInt() + it32 = gatomic.NewInt32() + it64 = gatomic.NewInt64() + uit = gatomic.NewUint() + uit32 = gatomic.NewUint32() + uit64 = gatomic.NewUint64() + bl = gatomic.NewBool() + vbytes = gatomic.NewBytes() + str = gatomic.NewString() + inf = gatomic.NewInterface() at = atomic.Value{} ) diff --git a/container/gtype/gtype_z_bench_json_test.go b/container/gatomic/gatomic_z_bench_json_test.go similarity index 75% rename from container/gtype/gtype_z_bench_json_test.go rename to container/gatomic/gatomic_z_bench_json_test.go index a2b4d2d40..e61d5ffd7 100644 --- a/container/gtype/gtype_z_bench_json_test.go +++ b/container/gatomic/gatomic_z_bench_json_test.go @@ -6,29 +6,29 @@ // go test *.go -bench=".+\_Json" -benchmem -package gtype_test +package gatomic_test import ( "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" ) var ( - vBool = gtype.NewBool() - vByte = gtype.NewByte() - vBytes = gtype.NewBytes() - vFloat32 = gtype.NewFloat32() - vFloat64 = gtype.NewFloat64() - vInt = gtype.NewInt() - vInt32 = gtype.NewInt32() - vInt64 = gtype.NewInt64() - vInterface = gtype.NewInterface() - vString = gtype.NewString() - vUint = gtype.NewUint() - vUint32 = gtype.NewUint32() - vUint64 = gtype.NewUint64() + vBool = gatomic.NewBool() + vByte = gatomic.NewByte() + vBytes = gatomic.NewBytes() + vFloat32 = gatomic.NewFloat32() + vFloat64 = gatomic.NewFloat64() + vInt = gatomic.NewInt() + vInt32 = gatomic.NewInt32() + vInt64 = gatomic.NewInt64() + vInterface = gatomic.NewInterface() + vString = gatomic.NewString() + vUint = gatomic.NewUint() + vUint32 = gatomic.NewUint32() + vUint64 = gatomic.NewUint64() ) func Benchmark_Bool_Json(b *testing.B) { diff --git a/container/gpool/gpool.go b/container/gpool/gpool.go index f07b20d91..c77edfebc 100644 --- a/container/gpool/gpool.go +++ b/container/gpool/gpool.go @@ -11,8 +11,8 @@ import ( "context" "time" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/glist" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/os/gtime" @@ -22,7 +22,7 @@ import ( // Pool is an Object-Reusable Pool. type Pool struct { list *glist.List // Available/idle items list. - closed *gtype.Bool // Whether the pool is closed. + closed *gatomic.Bool // Whether the pool is closed. TTL time.Duration // Time To Live for pool items. NewFunc func() (interface{}, error) // Callback function to create pool item. // ExpireFunc is the function for expired items destruction. @@ -54,7 +54,7 @@ type ExpireFunc func(interface{}) func New(ttl time.Duration, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool { r := &Pool{ list: glist.New(true), - closed: gtype.NewBool(), + closed: gatomic.NewBool(), TTL: ttl, NewFunc: newFunc, } diff --git a/container/gpool/gpool_z_unit_test.go b/container/gpool/gpool_z_unit_test.go index 1f964869c..cd99ae51b 100644 --- a/container/gpool/gpool_z_unit_test.go +++ b/container/gpool/gpool_z_unit_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gpool" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/frame/g" "github.com/gogf/gf/v3/test/gtest" ) @@ -21,7 +21,7 @@ var nf gpool.NewFunc = func() (i interface{}, e error) { return "hello", nil } -var assertIndex = gtype.NewInt(0) +var assertIndex = gatomic.NewInt(0) var ef gpool.ExpireFunc = func(i interface{}) { assertIndex.Add(1) diff --git a/container/gqueue/gqueue.go b/container/gqueue/gqueue.go index 6c3959670..23ccd0fa3 100644 --- a/container/gqueue/gqueue.go +++ b/container/gqueue/gqueue.go @@ -20,15 +20,15 @@ package gqueue import ( "math" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/glist" - "github.com/gogf/gf/v3/container/gtype" ) // Queue is a concurrent-safe queue built on doubly linked list and channel. type Queue struct { limit int // Limit for queue size. list *glist.List // Underlying list structure for data maintaining. - closed *gtype.Bool // Whether queue is closed. + closed *gatomic.Bool // Whether queue is closed. events chan struct{} // Events for data writing. C chan interface{} // Underlying channel for data reading. } @@ -43,7 +43,7 @@ const ( // When `limit` is given, the queue will be static and high performance which is comparable with stdlib channel. func New(limit ...int) *Queue { q := &Queue{ - closed: gtype.NewBool(), + closed: gatomic.NewBool(), } if len(limit) > 0 && limit[0] > 0 { q.limit = limit[0] diff --git a/container/gring/gring.go b/container/gring/gring.go index 67dc8f63a..5d5f3cdde 100644 --- a/container/gring/gring.go +++ b/container/gring/gring.go @@ -12,7 +12,7 @@ package gring import ( "container/ring" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/rwmutex" ) @@ -21,10 +21,10 @@ import ( // Deprecated. type Ring struct { mu *rwmutex.RWMutex - ring *ring.Ring // Underlying ring. - len *gtype.Int // Length(already used size). - cap *gtype.Int // Capability(>=len). - dirty *gtype.Bool // Dirty, which means the len and cap should be recalculated. It's marked dirty when the size of ring changes. + ring *ring.Ring // Underlying ring. + len *gatomic.Int // Length(already used size). + cap *gatomic.Int // Capability(>=len). + dirty *gatomic.Bool // Dirty, which means the len and cap should be recalculated. It's marked dirty when the size of ring changes. } // internalRingItem stores the ring element value. @@ -41,9 +41,9 @@ func New(cap int, safe ...bool) *Ring { return &Ring{ mu: rwmutex.New(safe...), ring: ring.New(cap), - len: gtype.NewInt(), - cap: gtype.NewInt(cap), - dirty: gtype.NewBool(), + len: gatomic.NewInt(), + cap: gatomic.NewInt(cap), + dirty: gatomic.NewBool(), } } diff --git a/container/gvar/gvar.go b/container/gvar/gvar.go index 8c1986c52..ee82a9347 100644 --- a/container/gvar/gvar.go +++ b/container/gvar/gvar.go @@ -8,7 +8,7 @@ package gvar import ( - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/json" ) @@ -24,7 +24,7 @@ type Var struct { func New(value interface{}, safe ...bool) *Var { if len(safe) > 0 && safe[0] { return &Var{ - value: gtype.NewInterface(value), + value: gatomic.NewInterface(value), safe: true, } } diff --git a/container/gvar/gvar_basic.go b/container/gvar/gvar_basic.go index cf2479959..44ad44b69 100644 --- a/container/gvar/gvar_basic.go +++ b/container/gvar/gvar_basic.go @@ -7,7 +7,7 @@ package gvar import ( - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/util/gconv" ) @@ -17,7 +17,7 @@ func (v *Var) Val() any { return nil } if v.safe { - if t, ok := v.value.(*gtype.Interface); ok { + if t, ok := v.value.(*gatomic.Interface); ok { return t.Val() } } diff --git a/container/gvar/gvar_set.go b/container/gvar/gvar_set.go index 09f395012..e5dc9a0dc 100644 --- a/container/gvar/gvar_set.go +++ b/container/gvar/gvar_set.go @@ -7,13 +7,13 @@ package gvar import ( - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" ) // Set sets `value` to `v`, and returns the old value. func (v *Var) Set(value interface{}) (old interface{}) { if v.safe { - if t, ok := v.value.(*gtype.Interface); ok { + if t, ok := v.value.(*gatomic.Interface); ok { old = t.Set(value) return } diff --git a/contrib/registry/file/file_discovery.go b/contrib/registry/file/file_discovery.go index 7af8b3307..d40e9a31f 100644 --- a/contrib/registry/file/file_discovery.go +++ b/contrib/registry/file/file_discovery.go @@ -9,8 +9,8 @@ package file import ( "context" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gmap" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/frame/g" "github.com/gogf/gf/v3/net/gsvc" "github.com/gogf/gf/v3/os/gfile" @@ -56,7 +56,7 @@ func (r *Registry) Watch(ctx context.Context, key string) (watcher gsvc.Watcher, prefix: key, discovery: r, ch: make(chan gsvc.Service, 100), - closed: gtype.NewBool(false), + closed: gatomic.NewBool(false), } _, err = gfsnotify.Add(r.path, func(event *gfsnotify.Event) { if fileWatcher.closed.Val() { diff --git a/contrib/registry/file/file_watcher.go b/contrib/registry/file/file_watcher.go index d02bc2039..56c804d4c 100644 --- a/contrib/registry/file/file_watcher.go +++ b/contrib/registry/file/file_watcher.go @@ -9,7 +9,7 @@ package file import ( "context" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/net/gsvc" ) @@ -19,7 +19,7 @@ type Watcher struct { prefix string // Watched prefix key, not file name prefix. discovery gsvc.Discovery // Service discovery. ch chan gsvc.Service // Changes that caused by inotify. - closed *gtype.Bool // Whether the channel has been closed + closed *gatomic.Bool // Whether the channel has been closed } // Proceed proceeds watch in blocking way. diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 075cbe613..2a71b804e 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -13,8 +13,8 @@ import ( "time" "github.com/gogf/gf/v3/container/garray" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gmap" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/container/gvar" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" @@ -490,7 +490,7 @@ type Core struct { db DB // DB interface object. group string // Configuration group name. schema string // Custom schema for this object. - debug *gtype.Bool // Enable debug mode for the database, which can be changed in runtime. + debug *gatomic.Bool // Enable debug mode for the database, which can be changed in runtime. cache *gcache.Cache // Cache manager, SQL result cache only. links *gmap.Map // links caches all created links by node. logger glog.ILogger // Logger for logging functionality. @@ -905,7 +905,7 @@ func newDBByConfigNode(node *ConfigNode, group string) (db DB, err error) { } c := &Core{ group: group, - debug: gtype.NewBool(), + debug: gatomic.NewBool(), cache: gcache.New(), links: gmap.New(true), logger: glog.New(), diff --git a/database/gdb/gdb_core_transaction.go b/database/gdb/gdb_core_transaction.go index 05302f607..996a46ab2 100644 --- a/database/gdb/gdb_core_transaction.go +++ b/database/gdb/gdb_core_transaction.go @@ -10,7 +10,7 @@ import ( "context" "database/sql" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" ) @@ -65,7 +65,7 @@ const ( transactionIdForLoggerCtx = "TransactionId" ) -var transactionIdGenerator = gtype.NewUint64() +var transactionIdGenerator = gatomic.NewUint64() // DefaultTxOptions returns the default transaction options. func DefaultTxOptions() TxOptions { diff --git a/internal/tracing/tracing.go b/internal/tracing/tracing.go index 49f4e3ea8..b648e1550 100644 --- a/internal/tracing/tracing.go +++ b/internal/tracing/tracing.go @@ -13,14 +13,14 @@ import ( "go.opentelemetry.io/otel/trace" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/encoding/gbinary" "github.com/gogf/gf/v3/util/grand" ) var ( randomInitSequence = int32(grand.Intn(math.MaxInt32)) - sequence = gtype.NewInt32(randomInitSequence) + sequence = gatomic.NewInt32(randomInitSequence) ) // NewIDs creates and returns a new trace and span ID. diff --git a/net/ghttp/ghttp.go b/net/ghttp/ghttp.go index bab6aeff4..5d04cb4fe 100644 --- a/net/ghttp/ghttp.go +++ b/net/ghttp/ghttp.go @@ -15,8 +15,8 @@ import ( "github.com/gorilla/websocket" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gmap" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/net/ghttp/internal/graceful" @@ -36,7 +36,7 @@ type ( config ServerConfig // Server configuration. plugins []Plugin // Plugin array to extend server functionality. servers []*graceful.Server // Underlying http.Server array. - serverCount *gtype.Int // Underlying http.Server number for internal usage. + serverCount *gatomic.Int // Underlying http.Server number for internal usage. closeChan chan struct{} // Used for underlying server closing event notification. serveTree map[string]interface{} // The route maps tree. serveCache *gcache.Cache // Server caches for internal usage. @@ -182,7 +182,7 @@ var ( // serverRunning marks the running server counts. // If there is no successful server running or all servers' shutdown, this value is 0. - serverRunning = gtype.NewInt() + serverRunning = gatomic.NewInt() // wsUpGrader is the default up-grader configuration for websocket. wsUpGrader = websocket.Upgrader{ @@ -197,7 +197,7 @@ var ( // serverProcessInitialized is used for lazy initialization for server. // The process can only be initialized once. - serverProcessInitialized = gtype.NewBool() + serverProcessInitialized = gatomic.NewBool() // gracefulEnabled is used for a graceful reload feature, which is false in default. gracefulEnabled = false diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index ae27fddb0..5c85add7a 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -20,8 +20,8 @@ import ( "github.com/olekukonko/tablewriter" "github.com/gogf/gf/v3/container/garray" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gset" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/debug/gdebug" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" @@ -100,7 +100,7 @@ func GetServer(name ...interface{}) *Server { plugins: make([]Plugin, 0), servers: make([]*graceful.Server, 0), closeChan: make(chan struct{}, 10000), - serverCount: gtype.NewInt(), + serverCount: gatomic.NewInt(), statusHandlerMap: make(map[string][]HandlerFunc), serveTree: make(map[string]interface{}), serveCache: gcache.New(), diff --git a/net/ghttp/ghttp_server_admin_process.go b/net/ghttp/ghttp_server_admin_process.go index e1196e06d..6f4dd934a 100644 --- a/net/ghttp/ghttp_server_admin_process.go +++ b/net/ghttp/ghttp_server_admin_process.go @@ -16,7 +16,7 @@ import ( "sync" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/encoding/gjson" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" @@ -46,10 +46,10 @@ var ( serverActionLocker sync.Mutex // serverActionLastTime is timestamp in milliseconds of last administration operation. - serverActionLastTime = gtype.NewInt64(gtime.TimestampMilli()) + serverActionLastTime = gatomic.NewInt64(gtime.TimestampMilli()) // serverProcessStatus is the server status for operation of current process. - serverProcessStatus = gtype.NewInt() + serverProcessStatus = gatomic.NewInt() ) // RestartAllServer restarts all the servers of the process gracefully. diff --git a/net/ghttp/ghttp_server_router.go b/net/ghttp/ghttp_server_router.go index 2d0a755bb..1b85da5b6 100644 --- a/net/ghttp/ghttp_server_router.go +++ b/net/ghttp/ghttp_server_router.go @@ -13,8 +13,8 @@ import ( "runtime" "strings" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/glist" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/debug/gdebug" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" @@ -27,7 +27,7 @@ import ( var ( // handlerIdGenerator is handler item id generator. - handlerIdGenerator = gtype.NewInt() + handlerIdGenerator = gatomic.NewInt() ) // routerMapKey creates and returns a unique router key for given parameters. diff --git a/net/ghttp/internal/graceful/graceful.go b/net/ghttp/internal/graceful/graceful.go index bf58928d2..d649cca55 100644 --- a/net/ghttp/internal/graceful/graceful.go +++ b/net/ghttp/internal/graceful/graceful.go @@ -30,7 +30,7 @@ import ( "sync" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/os/glog" @@ -60,7 +60,7 @@ type Server struct { rawLnMu sync.RWMutex // Concurrent safety mutex for rawListener. listener net.Listener // Wrapped net.Listener with TLS support if necessary. isHttps bool // Whether server is running in HTTPS mode. - status *gtype.Int // Server status using gtype for concurrent safety. + status *gatomic.Int // Server status using gtype for concurrent safety. config ServerConfig // Server configuration. } @@ -127,7 +127,7 @@ func New( gs := &Server{ address: address, httpServer: newHttpServer(address, loggerWriter, config), - status: gtype.NewInt(), + status: gatomic.NewInt(), config: config, } if fd != 0 { diff --git a/net/gsel/gsel_selector_least_connection.go b/net/gsel/gsel_selector_least_connection.go index 5d83aa705..406fbf913 100644 --- a/net/gsel/gsel_selector_least_connection.go +++ b/net/gsel/gsel_selector_least_connection.go @@ -10,7 +10,7 @@ import ( "context" "sync" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/internal/intlog" ) @@ -21,7 +21,7 @@ type selectorLeastConnection struct { type leastConnectionNode struct { Node - inflight *gtype.Int + inflight *gatomic.Int } func NewSelectorLeastConnection() Selector { @@ -37,7 +37,7 @@ func (s *selectorLeastConnection) Update(ctx context.Context, nodes Nodes) error node := v newNodes = append(newNodes, &leastConnectionNode{ Node: node, - inflight: gtype.NewInt(), + inflight: gatomic.NewInt(), }) } s.mu.Lock() diff --git a/os/gcache/gcache_adapter_memory.go b/os/gcache/gcache_adapter_memory.go index 4f7d74137..bf48bdc04 100644 --- a/os/gcache/gcache_adapter_memory.go +++ b/os/gcache/gcache_adapter_memory.go @@ -11,9 +11,9 @@ import ( "math" "time" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/glist" "github.com/gogf/gf/v3/container/gset" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/container/gvar" "github.com/gogf/gf/v3/os/gtime" "github.com/gogf/gf/v3/os/gtimer" @@ -26,7 +26,7 @@ type AdapterMemory struct { expireSets *memoryExpireSets // expireSets is the expiring timestamp to its key set mapping, which is used for quick indexing and deleting. lru *memoryLru // lru is the LRU manager, which is enabled when attribute cap > 0. eventList *glist.List // eventList is the asynchronous event list for internal data synchronization. - closed *gtype.Bool // closed controls the cache closed or not. + closed *gatomic.Bool // closed controls the cache closed or not. } // Internal event item. @@ -60,7 +60,7 @@ func doNewAdapterMemory() *AdapterMemory { expireTimes: newMemoryExpireTimes(), expireSets: newMemoryExpireSets(), eventList: glist.New(true), - closed: gtype.NewBool(), + closed: gatomic.NewBool(), } // Here may be a "timer leak" if adapter is manually changed from adapter_memory adapter. // Do not worry about this, as adapter is less changed, and it does nothing if it's not used. diff --git a/os/gcron/gcron_cron.go b/os/gcron/gcron_cron.go index 75b337adf..474d03540 100644 --- a/os/gcron/gcron_cron.go +++ b/os/gcron/gcron_cron.go @@ -12,16 +12,16 @@ import ( "time" "github.com/gogf/gf/v3/container/garray" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gmap" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/os/glog" "github.com/gogf/gf/v3/os/gtimer" ) // Cron stores all the cron job entries. type Cron struct { - idGen *gtype.Int64 // Used for unique name generation. - status *gtype.Int // Timed task status(0: Not Start; 1: Running; 2: Stopped; -1: Closed) + idGen *gatomic.Int64 // Used for unique name generation. + status *gatomic.Int // Timed task status(0: Not Start; 1: Running; 2: Stopped; -1: Closed) entries *gmap.StrAnyMap // All timed task entries. logger glog.ILogger // Logger, it is nil in default. jobWaiter sync.WaitGroup // Graceful shutdown when cron jobs are stopped. @@ -30,8 +30,8 @@ type Cron struct { // New returns a new Cron object with default settings. func New() *Cron { return &Cron{ - idGen: gtype.NewInt64(), - status: gtype.NewInt(StatusRunning), + idGen: gatomic.NewInt64(), + status: gatomic.NewInt(StatusRunning), entries: gmap.NewStrAnyMap(true), } } diff --git a/os/gcron/gcron_entry.go b/os/gcron/gcron_entry.go index 0379867bb..96c3e94f0 100644 --- a/os/gcron/gcron_entry.go +++ b/os/gcron/gcron_entry.go @@ -13,7 +13,7 @@ import ( "runtime" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/os/glog" @@ -30,8 +30,8 @@ type Entry struct { timerEntry *gtimer.Entry // Associated timer Entry. schedule *cronSchedule // Timed schedule object. jobName string // Callback function name(address info). - times *gtype.Int // Running times limit. - infinite *gtype.Bool // No times limit. + times *gatomic.Int // Running times limit. + infinite *gatomic.Bool // No times limit. Name string // Entry name. RegisterTime time.Time // Registered time. Job JobFunc `json:"-"` // Callback function. @@ -67,8 +67,8 @@ func (c *Cron) doAddEntry(in doAddEntryInput) (*Entry, error) { cron: c, schedule: schedule, jobName: runtime.FuncForPC(reflect.ValueOf(in.Job).Pointer()).Name(), - times: gtype.NewInt(in.Times), - infinite: gtype.NewBool(in.Infinite), + times: gatomic.NewInt(in.Times), + infinite: gatomic.NewBool(in.Infinite), RegisterTime: time.Now(), Job: in.Job, } diff --git a/os/gcron/gcron_schedule.go b/os/gcron/gcron_schedule.go index 7b40c6750..cd8b6413d 100644 --- a/os/gcron/gcron_schedule.go +++ b/os/gcron/gcron_schedule.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/os/gtime" @@ -32,10 +32,10 @@ type cronSchedule struct { monthMap map[int]struct{} // Job can run in these moth numbers. // This field stores the timestamp that meets schedule latest. - lastMeetTimestamp *gtype.Int64 + lastMeetTimestamp *gatomic.Int64 // Last timestamp number, for timestamp fix in some latency. - lastCheckTimestamp *gtype.Int64 + lastCheckTimestamp *gatomic.Int64 } type patternItemType int @@ -134,8 +134,8 @@ func newSchedule(pattern string) (*cronSchedule, error) { createTimestamp: currentTimestamp, everySeconds: int64(d.Seconds()), pattern: pattern, - lastMeetTimestamp: gtype.NewInt64(currentTimestamp), - lastCheckTimestamp: gtype.NewInt64(currentTimestamp), + lastMeetTimestamp: gatomic.NewInt64(currentTimestamp), + lastCheckTimestamp: gatomic.NewInt64(currentTimestamp), }, nil } else { return nil, gerror.NewCodef(gcode.CodeInvalidParameter, `invalid pattern: "%s"`, pattern) @@ -152,8 +152,8 @@ func newSchedule(pattern string) (*cronSchedule, error) { createTimestamp: currentTimestamp, everySeconds: 0, pattern: pattern, - lastMeetTimestamp: gtype.NewInt64(currentTimestamp), - lastCheckTimestamp: gtype.NewInt64(currentTimestamp), + lastMeetTimestamp: gatomic.NewInt64(currentTimestamp), + lastCheckTimestamp: gatomic.NewInt64(currentTimestamp), } ) diff --git a/os/gfile/gfile.go b/os/gfile/gfile.go index dae2c840c..829840a23 100644 --- a/os/gfile/gfile.go +++ b/os/gfile/gfile.go @@ -14,7 +14,7 @@ import ( "strings" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/text/gstr" "github.com/gogf/gf/v3/util/gconv" @@ -36,7 +36,7 @@ const ( var ( // The absolute file path for main package. // It can be only checked and set once. - mainPkgPath = gtype.NewString() + mainPkgPath = gatomic.NewString() // selfPath is the current running binary path. // As it is most commonly used, it is so defined as an internal package variable. diff --git a/os/gfpool/gfpool.go b/os/gfpool/gfpool.go index 70ad7ebdd..91cd3e740 100644 --- a/os/gfpool/gfpool.go +++ b/os/gfpool/gfpool.go @@ -11,16 +11,16 @@ import ( "os" "time" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gmap" "github.com/gogf/gf/v3/container/gpool" - "github.com/gogf/gf/v3/container/gtype" ) // Pool pointer pool. type Pool struct { - id *gtype.Int // Pool id, which is used to mark this pool whether recreated. + id *gatomic.Int // Pool id, which is used to mark this pool whether recreated. pool *gpool.Pool // Underlying pool. - init *gtype.Bool // Whether initialized, used for marking this file added to fsnotify, and it can only be added just once. + init *gatomic.Bool // Whether initialized, used for marking this file added to fsnotify, and it can only be added just once. ttl time.Duration // Time to live for file pointer items. } diff --git a/os/gfpool/gfpool_pool.go b/os/gfpool/gfpool_pool.go index 5bc79e324..05804180d 100644 --- a/os/gfpool/gfpool_pool.go +++ b/os/gfpool/gfpool_pool.go @@ -10,8 +10,8 @@ import ( "os" "time" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gpool" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/os/gfsnotify" ) @@ -29,9 +29,9 @@ func New(path string, flag int, perm os.FileMode, ttl ...time.Duration) *Pool { fpTTL = ttl[0] } p := &Pool{ - id: gtype.NewInt(), + id: gatomic.NewInt(), ttl: fpTTL, - init: gtype.NewBool(), + init: gatomic.NewBool(), } p.pool = newFilePool(p, path, flag, perm, fpTTL) return p diff --git a/os/gfsnotify/gfsnotify.go b/os/gfsnotify/gfsnotify.go index 771eb4498..ea8859851 100644 --- a/os/gfsnotify/gfsnotify.go +++ b/os/gfsnotify/gfsnotify.go @@ -14,11 +14,11 @@ import ( "github.com/fsnotify/fsnotify" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/glist" "github.com/gogf/gf/v3/container/gmap" "github.com/gogf/gf/v3/container/gqueue" "github.com/gogf/gf/v3/container/gset" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/internal/intlog" @@ -85,7 +85,7 @@ var ( mu sync.Mutex // Mutex for concurrent safety of defaultWatcher. defaultWatcher *Watcher // Default watcher. callbackIdMap = gmap.NewIntAnyMap(true) // Global callback id to callback function mapping. - callbackIdGenerator = gtype.NewInt() // Atomic id generator for callback. + callbackIdGenerator = gatomic.NewInt() // Atomic id generator for callback. ) // New creates and returns a new watcher. diff --git a/os/gfsnotify/gfsnotify_z_unit_test.go b/os/gfsnotify/gfsnotify_z_unit_test.go index 39ec26a7d..261c6d6a5 100644 --- a/os/gfsnotify/gfsnotify_z_unit_test.go +++ b/os/gfsnotify/gfsnotify_z_unit_test.go @@ -11,7 +11,7 @@ import ( "time" "github.com/gogf/gf/v3/container/garray" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/os/gfile" "github.com/gogf/gf/v3/os/gfsnotify" "github.com/gogf/gf/v3/os/gtime" @@ -21,7 +21,7 @@ import ( func TestWatcher_AddOnce(t *testing.T) { gtest.C(t, func(t *gtest.T) { - value := gtype.New() + value := gatomic.New() path := gfile.Temp(gconv.String(gtime.TimestampNano())) err := gfile.PutContents(path, "init") t.AssertNil(err) @@ -64,7 +64,7 @@ func TestWatcher_AddRemove(t *testing.T) { gfile.Remove(path1) gfile.Remove(path2) }() - v := gtype.NewInt(1) + v := gatomic.NewInt(1) callback, err := gfsnotify.Add(path1, func(event *gfsnotify.Event) { if event.IsWrite() { v.Set(2) @@ -94,7 +94,7 @@ func TestWatcher_AddRemove(t *testing.T) { defer func() { gfile.Remove(path1) }() - v := gtype.NewInt(1) + v := gatomic.NewInt(1) callback, err := gfsnotify.Add(path1, func(event *gfsnotify.Event) { if event.IsWrite() { v.Set(2) @@ -129,7 +129,7 @@ func TestWatcher_Callback1(t *testing.T) { defer func() { gfile.Remove(path1) }() - v := gtype.NewInt(1) + v := gatomic.NewInt(1) callback, err := gfsnotify.Add(path1, func(event *gfsnotify.Event) { if event.IsWrite() { v.Set(2) @@ -159,8 +159,8 @@ func TestWatcher_Callback2(t *testing.T) { defer func() { gfile.Remove(path1) }() - v1 := gtype.NewInt(1) - v2 := gtype.NewInt(1) + v1 := gatomic.NewInt(1) + v2 := gatomic.NewInt(1) callback1, err1 := gfsnotify.Add(path1, func(event *gfsnotify.Event) { if event.IsWrite() { v1.Set(2) diff --git a/os/glog/glog_logger_config.go b/os/glog/glog_logger_config.go index b2861d97f..8576d3617 100644 --- a/os/glog/glog_logger_config.go +++ b/os/glog/glog_logger_config.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/internal/intlog" @@ -51,7 +51,7 @@ type Config struct { } type internalConfig struct { - rotatedHandlerInitialized *gtype.Bool // Whether the rotation feature initialized. + rotatedHandlerInitialized *gatomic.Bool // Whether the rotation feature initialized. } // DefaultConfig returns the default configuration for logger. @@ -69,7 +69,7 @@ func DefaultConfig() Config { LevelPrefixes: make(map[int]string, len(defaultLevelPrefixes)), RotateCheckInterval: time.Hour, internalConfig: internalConfig{ - rotatedHandlerInitialized: gtype.NewBool(), + rotatedHandlerInitialized: gatomic.NewBool(), }, } for k, v := range defaultLevelPrefixes { diff --git a/os/gproc/gproc_comm_receive.go b/os/gproc/gproc_comm_receive.go index 6eb5947b1..f8677918b 100644 --- a/os/gproc/gproc_comm_receive.go +++ b/os/gproc/gproc_comm_receive.go @@ -11,8 +11,8 @@ import ( "fmt" "net" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gqueue" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/internal/json" "github.com/gogf/gf/v3/net/gtcp" @@ -23,7 +23,7 @@ import ( var ( // tcpListened marks whether the receiving listening service started. - tcpListened = gtype.NewBool() + tcpListened = gatomic.NewBool() ) // Receive blocks and receives message from other process using local TCP listening. diff --git a/os/grpool/grpool.go b/os/grpool/grpool.go index 877a5878d..81ae7f804 100644 --- a/os/grpool/grpool.go +++ b/os/grpool/grpool.go @@ -11,8 +11,8 @@ import ( "context" "time" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/glist" - "github.com/gogf/gf/v3/container/gtype" "github.com/gogf/gf/v3/os/gtimer" "github.com/gogf/gf/v3/util/grand" ) @@ -25,10 +25,10 @@ type RecoverFunc func(ctx context.Context, exception error) // Pool manages the goroutines using pool. type Pool struct { - limit int // Max goroutine count limit. - count *gtype.Int // Current running goroutine count. - list *glist.List // List for asynchronous job adding purpose. - closed *gtype.Bool // Is pool closed or not. + limit int // Max goroutine count limit. + count *gatomic.Int // Current running goroutine count. + list *glist.List // List for asynchronous job adding purpose. + closed *gatomic.Bool // Is pool closed or not. } // localPoolItem is the job item storing in job list. @@ -54,9 +54,9 @@ func New(limit ...int) *Pool { var ( pool = &Pool{ limit: -1, - count: gtype.NewInt(), + count: gatomic.NewInt(), list: glist.New(true), - closed: gtype.NewBool(), + closed: gatomic.NewBool(), } timerDuration = grand.D( minSupervisorTimerDuration, diff --git a/os/gtimer/gtimer.go b/os/gtimer/gtimer.go index 13ad8e821..ef3befc6c 100644 --- a/os/gtimer/gtimer.go +++ b/os/gtimer/gtimer.go @@ -24,7 +24,7 @@ import ( "sync" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" "github.com/gogf/gf/v3/internal/command" @@ -34,8 +34,8 @@ import ( type Timer struct { mu sync.RWMutex queue *priorityQueue // queue is a priority queue based on heap structure. - status *gtype.Int // status is the current timer status. - ticks *gtype.Int64 // ticks is the proceeded interval number by the timer. + status *gatomic.Int // status is the current timer status. + ticks *gatomic.Int64 // ticks is the proceeded interval number by the timer. options TimerOptions // timer options is used for timer configuration. } diff --git a/os/gtimer/gtimer_entry.go b/os/gtimer/gtimer_entry.go index 67573b023..86f429ac5 100644 --- a/os/gtimer/gtimer_entry.go +++ b/os/gtimer/gtimer_entry.go @@ -9,7 +9,7 @@ package gtimer import ( "context" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" ) @@ -20,11 +20,11 @@ type Entry struct { ctx context.Context // The context for the job, for READ ONLY. timer *Timer // Belonged timer. ticks int64 // The job runs every tick. - times *gtype.Int // Limit running times. - status *gtype.Int // Job status. - isSingleton *gtype.Bool // Singleton mode. - nextTicks *gtype.Int64 // Next run ticks of the job. - infinite *gtype.Bool // No times limit. + times *gatomic.Int // Limit running times. + status *gatomic.Int // Job status. + isSingleton *gatomic.Bool // Singleton mode. + nextTicks *gatomic.Int64 // Next run ticks of the job. + infinite *gatomic.Bool // No times limit. } // JobFunc is the timing called job function in timer. diff --git a/os/gtimer/gtimer_queue.go b/os/gtimer/gtimer_queue.go index 600560ba2..a2f00507d 100644 --- a/os/gtimer/gtimer_queue.go +++ b/os/gtimer/gtimer_queue.go @@ -11,7 +11,7 @@ import ( "math" "sync" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" ) // priorityQueue is an abstract data type similar to a regular queue or stack data structure in which @@ -21,7 +21,7 @@ import ( type priorityQueue struct { mu sync.Mutex heap *priorityQueueHeap // the underlying queue items manager using heap. - nextPriority *gtype.Int64 // nextPriority stores the next priority value of the heap, which is used to check if necessary to call the Pop of heap by Timer. + nextPriority *gatomic.Int64 // nextPriority stores the next priority value of the heap, which is used to check if necessary to call the Pop of heap by Timer. } // priorityQueueHeap is a heap manager, of which the underlying `array` is an array implementing a heap structure. @@ -39,7 +39,7 @@ type priorityQueueItem struct { func newPriorityQueue() *priorityQueue { queue := &priorityQueue{ heap: &priorityQueueHeap{array: make([]priorityQueueItem, 0)}, - nextPriority: gtype.NewInt64(math.MaxInt64), + nextPriority: gatomic.NewInt64(math.MaxInt64), } heap.Init(queue.heap) return queue diff --git a/os/gtimer/gtimer_timer.go b/os/gtimer/gtimer_timer.go index 5cf9213f1..48e19cf86 100644 --- a/os/gtimer/gtimer_timer.go +++ b/os/gtimer/gtimer_timer.go @@ -10,15 +10,15 @@ import ( "context" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" ) // New creates and returns a Timer. func New(options ...TimerOptions) *Timer { t := &Timer{ queue: newPriorityQueue(), - status: gtype.NewInt(StatusRunning), - ticks: gtype.NewInt64(), + status: gatomic.NewInt(StatusRunning), + ticks: gatomic.NewInt64(), } if len(options) > 0 { t.options = options[0] @@ -196,11 +196,11 @@ func (t *Timer) createEntry(in createEntryInput) *Entry { ctx: in.Ctx, timer: t, ticks: intervalTicksOfJob, - times: gtype.NewInt(in.Times), - status: gtype.NewInt(in.Status), - isSingleton: gtype.NewBool(in.IsSingleton), - nextTicks: gtype.NewInt64(nextTicks), - infinite: gtype.NewBool(infinite), + times: gatomic.NewInt(in.Times), + status: gatomic.NewInt(in.Status), + isSingleton: gatomic.NewBool(in.IsSingleton), + nextTicks: gatomic.NewInt64(nextTicks), + infinite: gatomic.NewBool(infinite), } ) t.queue.Push(entry, nextTicks) diff --git a/util/gconv/gconv_z_unit_issue_test.go b/util/gconv/gconv_z_unit_issue_test.go index 685434340..a8bec2bcd 100644 --- a/util/gconv/gconv_z_unit_issue_test.go +++ b/util/gconv/gconv_z_unit_issue_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/container/gvar" "github.com/gogf/gf/v3/encoding/gjson" "github.com/gogf/gf/v3/frame/g" @@ -152,7 +152,7 @@ func Test_Issue1607(t *testing.T) { func Test_Issue1946(t *testing.T) { gtest.C(t, func(t *gtest.T) { type B struct { - init *gtype.Bool + init *gatomic.Bool Name string } type A struct { @@ -160,7 +160,7 @@ func Test_Issue1946(t *testing.T) { } a := &A{ B: &B{ - init: gtype.NewBool(true), + init: gatomic.NewBool(true), }, } err := gconv.Struct(g.Map{ @@ -175,7 +175,7 @@ func Test_Issue1946(t *testing.T) { // It cannot change private attribute. gtest.C(t, func(t *gtest.T) { type B struct { - init *gtype.Bool + init *gatomic.Bool Name string } type A struct { @@ -183,7 +183,7 @@ func Test_Issue1946(t *testing.T) { } a := &A{ B: &B{ - init: gtype.NewBool(true), + init: gatomic.NewBool(true), }, } err := gconv.Struct(g.Map{ @@ -199,7 +199,7 @@ func Test_Issue1946(t *testing.T) { // It can change public attribute. gtest.C(t, func(t *gtest.T) { type B struct { - Init *gtype.Bool + Init *gatomic.Bool Name string } type A struct { @@ -207,7 +207,7 @@ func Test_Issue1946(t *testing.T) { } a := &A{ B: &B{ - Init: gtype.NewBool(), + Init: gatomic.NewBool(), }, } err := gconv.Struct(g.Map{ @@ -733,12 +733,12 @@ func Test_Issue3821(t *testing.T) { type User struct { InnerUser - UserId int `orm:"user_id"` - UserIdBool gtype.Bool `orm:"user_id"` - Username string `orm:"user_name"` - Username2 string `orm:"user_name"` - Username3 *string `orm:"user_name"` - Username4 string `orm:"username"` // empty string + UserId int `orm:"user_id"` + UserIdBool gatomic.Bool `orm:"user_id"` + Username string `orm:"user_name"` + Username2 string `orm:"user_name"` + Username3 *string `orm:"user_name"` + Username4 string `orm:"username"` // empty string } var user = &User{} err := gconv.StructTag(record, user, "orm") diff --git a/util/guid/guid.go b/util/guid/guid.go index 77b95600f..7c2278fe0 100644 --- a/util/guid/guid.go +++ b/util/guid/guid.go @@ -12,7 +12,7 @@ import ( "strconv" "time" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/encoding/ghash" "github.com/gogf/gf/v3/errors/gcode" "github.com/gogf/gf/v3/errors/gerror" @@ -26,9 +26,9 @@ const ( ) var ( - sequence gtype.Uint32 // Sequence for unique purpose of the current process. - macAddrStr = "0000000" // Hash result of MAC addresses in 7 bytes. - processIdStr = "0000" // Process id in 4 bytes. + sequence gatomic.Uint32 // Sequence for unique purpose of the current process. + macAddrStr = "0000000" // Hash result of MAC addresses in 7 bytes. + processIdStr = "0000" // Process id in 4 bytes. ) // init initializes several fixed local variable. diff --git a/util/gutil/gutil_z_unit_dump_test.go b/util/gutil/gutil_z_unit_dump_test.go index a12814060..22acca928 100755 --- a/util/gutil/gutil_z_unit_dump_test.go +++ b/util/gutil/gutil_z_unit_dump_test.go @@ -10,7 +10,7 @@ import ( "bytes" "testing" - "github.com/gogf/gf/v3/container/gtype" + "github.com/gogf/gf/v3/container/gatomic" "github.com/gogf/gf/v3/frame/g" "github.com/gogf/gf/v3/net/ghttp" "github.com/gogf/gf/v3/os/gtime" @@ -76,7 +76,7 @@ func Test_Dump(t *testing.T) { gutil.Dump(make(chan int)) gutil.Dump(func() {}) gutil.Dump(nil) - gutil.Dump(gtype.NewInt(1)) + gutil.Dump(gatomic.NewInt(1)) }) }