mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 09:48:32 +02: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"
|
"net/http"
|
||||||
|
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
|
||||||
"github.com/yusing/goutils/server"
|
"github.com/yusing/goutils/server"
|
||||||
|
"github.com/yusing/goutils/synk"
|
||||||
"github.com/yusing/goutils/task"
|
"github.com/yusing/goutils/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,4 +31,4 @@ type State interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// could be nil
|
// 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/route/routes"
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
U "github.com/yusing/godoxy/internal/utils"
|
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/events"
|
||||||
"github.com/yusing/godoxy/internal/watcher/health/monitor"
|
"github.com/yusing/godoxy/internal/watcher/health/monitor"
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
"github.com/yusing/goutils/http/reverseproxy"
|
"github.com/yusing/goutils/http/reverseproxy"
|
||||||
|
"github.com/yusing/goutils/synk"
|
||||||
"github.com/yusing/goutils/task"
|
"github.com/yusing/goutils/task"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"golang.org/x/sync/singleflight"
|
"golang.org/x/sync/singleflight"
|
||||||
@@ -54,8 +54,8 @@ type (
|
|||||||
|
|
||||||
provider idlewatcher.Provider
|
provider idlewatcher.Provider
|
||||||
|
|
||||||
state atomic.Value[*containerState]
|
state synk.Value[*containerState]
|
||||||
lastReset atomic.Value[time.Time]
|
lastReset synk.Value[time.Time]
|
||||||
|
|
||||||
idleTicker *time.Ticker
|
idleTicker *time.Ticker
|
||||||
healthTicker *time.Ticker
|
healthTicker *time.Ticker
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import (
|
|||||||
|
|
||||||
"github.com/bytedance/sonic"
|
"github.com/bytedance/sonic"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
|
"github.com/yusing/goutils/synk"
|
||||||
"github.com/yusing/goutils/task"
|
"github.com/yusing/goutils/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ type (
|
|||||||
aggregate AggregateFunc[T, AggregateT]
|
aggregate AggregateFunc[T, AggregateT]
|
||||||
resultFilter FilterFunc[T]
|
resultFilter FilterFunc[T]
|
||||||
period *Period[T]
|
period *Period[T]
|
||||||
lastResult atomic.Value[T]
|
lastResult synk.Value[T]
|
||||||
errs []pollErr
|
errs []pollErr
|
||||||
}
|
}
|
||||||
pollErr struct {
|
pollErr struct {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/yusing/godoxy/internal/common"
|
"github.com/yusing/godoxy/internal/common"
|
||||||
nettypes "github.com/yusing/godoxy/internal/net/types"
|
nettypes "github.com/yusing/godoxy/internal/net/types"
|
||||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
|
||||||
strutils "github.com/yusing/goutils/strings"
|
strutils "github.com/yusing/goutils/strings"
|
||||||
|
"github.com/yusing/goutils/synk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cloudflareRealIP struct {
|
type cloudflareRealIP struct {
|
||||||
@@ -30,7 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfCIDRsLastUpdate atomic.Value[time.Time]
|
cfCIDRsLastUpdate synk.Value[time.Time]
|
||||||
cfCIDRsMu sync.Mutex
|
cfCIDRsMu sync.Mutex
|
||||||
|
|
||||||
// RFC 1918.
|
// 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"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
@@ -14,9 +15,9 @@ import (
|
|||||||
"github.com/yusing/godoxy/internal/docker"
|
"github.com/yusing/godoxy/internal/docker"
|
||||||
"github.com/yusing/godoxy/internal/notif"
|
"github.com/yusing/godoxy/internal/notif"
|
||||||
"github.com/yusing/godoxy/internal/types"
|
"github.com/yusing/godoxy/internal/types"
|
||||||
"github.com/yusing/godoxy/internal/utils/atomic"
|
|
||||||
gperr "github.com/yusing/goutils/errs"
|
gperr "github.com/yusing/goutils/errs"
|
||||||
strutils "github.com/yusing/goutils/strings"
|
strutils "github.com/yusing/goutils/strings"
|
||||||
|
"github.com/yusing/goutils/synk"
|
||||||
"github.com/yusing/goutils/task"
|
"github.com/yusing/goutils/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,10 +26,10 @@ type (
|
|||||||
monitor struct {
|
monitor struct {
|
||||||
service string
|
service string
|
||||||
config *types.HealthCheckConfig
|
config *types.HealthCheckConfig
|
||||||
url atomic.Value[*url.URL]
|
url synk.Value[*url.URL]
|
||||||
|
|
||||||
status atomic.Value[types.HealthStatus]
|
status synk.Value[types.HealthStatus]
|
||||||
lastResult atomic.Value[types.HealthCheckResult]
|
lastResult synk.Value[types.HealthCheckResult]
|
||||||
|
|
||||||
checkHealth HealthCheckFunc
|
checkHealth HealthCheckFunc
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
|
|||||||
Reference in New Issue
Block a user