mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
refract(container/gtype): rename package gtype to gatomic (#4274)
This commit is contained in:
@ -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) {
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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())
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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{}
|
||||
)
|
||||
|
||||
@ -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) {
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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.
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user