mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
refactor(utils): move utils/atomic to goutils
This commit is contained in:
2
goutils
2
goutils
Submodule goutils updated: b2336ee8a6...c9c0b8d9d0
@@ -6,8 +6,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
||||
"github.com/yusing/goutils/server"
|
||||
"github.com/yusing/goutils/synk"
|
||||
"github.com/yusing/goutils/task"
|
||||
)
|
||||
|
||||
@@ -31,4 +31,4 @@ type State interface {
|
||||
}
|
||||
|
||||
// could be nil
|
||||
var ActiveState atomic.Value[State]
|
||||
var ActiveState synk.Value[State]
|
||||
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
"github.com/yusing/godoxy/internal/route/routes"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
U "github.com/yusing/godoxy/internal/utils"
|
||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
||||
"github.com/yusing/godoxy/internal/watcher/events"
|
||||
"github.com/yusing/godoxy/internal/watcher/health/monitor"
|
||||
gperr "github.com/yusing/goutils/errs"
|
||||
"github.com/yusing/goutils/http/reverseproxy"
|
||||
"github.com/yusing/goutils/synk"
|
||||
"github.com/yusing/goutils/task"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"golang.org/x/sync/singleflight"
|
||||
@@ -54,8 +54,8 @@ type (
|
||||
|
||||
provider idlewatcher.Provider
|
||||
|
||||
state atomic.Value[*containerState]
|
||||
lastReset atomic.Value[time.Time]
|
||||
state synk.Value[*containerState]
|
||||
lastReset synk.Value[time.Time]
|
||||
|
||||
idleTicker *time.Ticker
|
||||
healthTicker *time.Ticker
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
||||
gperr "github.com/yusing/goutils/errs"
|
||||
"github.com/yusing/goutils/synk"
|
||||
"github.com/yusing/goutils/task"
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ type (
|
||||
aggregate AggregateFunc[T, AggregateT]
|
||||
resultFilter FilterFunc[T]
|
||||
period *Period[T]
|
||||
lastResult atomic.Value[T]
|
||||
lastResult synk.Value[T]
|
||||
errs []pollErr
|
||||
}
|
||||
pollErr struct {
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/godoxy/internal/common"
|
||||
nettypes "github.com/yusing/godoxy/internal/net/types"
|
||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
||||
strutils "github.com/yusing/goutils/strings"
|
||||
"github.com/yusing/goutils/synk"
|
||||
)
|
||||
|
||||
type cloudflareRealIP struct {
|
||||
@@ -30,7 +30,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
cfCIDRsLastUpdate atomic.Value[time.Time]
|
||||
cfCIDRsLastUpdate synk.Value[time.Time]
|
||||
cfCIDRsMu sync.Mutex
|
||||
|
||||
// RFC 1918.
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package atomic
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
type (
|
||||
Bool = atomic.Bool
|
||||
Int32 = atomic.Int32
|
||||
Int64 = atomic.Int64
|
||||
)
|
||||
@@ -1,35 +0,0 @@
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
type Value[T any] struct {
|
||||
atomic.Value
|
||||
}
|
||||
|
||||
func (a *Value[T]) Load() T {
|
||||
if v := a.Value.Load(); v != nil {
|
||||
return v.(T)
|
||||
}
|
||||
var zero T
|
||||
return zero
|
||||
}
|
||||
|
||||
func (a *Value[T]) Store(v T) {
|
||||
a.Value.Store(v)
|
||||
}
|
||||
|
||||
func (a *Value[T]) Swap(v T) T {
|
||||
if v := a.Value.Swap(v); v != nil {
|
||||
return v.(T)
|
||||
}
|
||||
var zero T
|
||||
return zero
|
||||
}
|
||||
|
||||
func (a *Value[T]) MarshalJSON() ([]byte, error) {
|
||||
return sonic.Marshal(a.Load())
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
@@ -14,9 +15,9 @@ import (
|
||||
"github.com/yusing/godoxy/internal/docker"
|
||||
"github.com/yusing/godoxy/internal/notif"
|
||||
"github.com/yusing/godoxy/internal/types"
|
||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
||||
gperr "github.com/yusing/goutils/errs"
|
||||
strutils "github.com/yusing/goutils/strings"
|
||||
"github.com/yusing/goutils/synk"
|
||||
"github.com/yusing/goutils/task"
|
||||
)
|
||||
|
||||
@@ -25,10 +26,10 @@ type (
|
||||
monitor struct {
|
||||
service string
|
||||
config *types.HealthCheckConfig
|
||||
url atomic.Value[*url.URL]
|
||||
url synk.Value[*url.URL]
|
||||
|
||||
status atomic.Value[types.HealthStatus]
|
||||
lastResult atomic.Value[types.HealthCheckResult]
|
||||
status synk.Value[types.HealthStatus]
|
||||
lastResult synk.Value[types.HealthCheckResult]
|
||||
|
||||
checkHealth HealthCheckFunc
|
||||
startTime time.Time
|
||||
|
||||
Reference in New Issue
Block a user