mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +02:00
improved health check
This commit is contained in:
30
internal/utils/atomic.go
Normal file
30
internal/utils/atomic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type AtomicValue[T any] struct {
|
||||
atomic.Value
|
||||
}
|
||||
|
||||
func (a *AtomicValue[T]) Load() T {
|
||||
return a.Value.Load().(T)
|
||||
}
|
||||
|
||||
func (a *AtomicValue[T]) Store(v T) {
|
||||
a.Value.Store(v)
|
||||
}
|
||||
|
||||
func (a *AtomicValue[T]) Swap(v T) T {
|
||||
return a.Value.Swap(v).(T)
|
||||
}
|
||||
|
||||
func (a *AtomicValue[T]) CompareAndSwap(oldV, newV T) bool {
|
||||
return a.Value.CompareAndSwap(oldV, newV)
|
||||
}
|
||||
|
||||
func (a *AtomicValue[T]) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(a.Load())
|
||||
}
|
||||
Reference in New Issue
Block a user