mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-11 03:06:51 +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())
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package functional
|
||||
|
||||
func FirstValueOf[KT comparable, VT any](m map[KT]VT) (_ VT, ok bool) {
|
||||
for _, v := range m {
|
||||
return v, true
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -98,6 +98,14 @@ func Serialize(data any) (SerializedObject, E.NestedError) {
|
||||
if jsonTag == "-" {
|
||||
continue // Ignore this field if the tag is "-"
|
||||
}
|
||||
if strings.Contains(jsonTag, ",omitempty") {
|
||||
if field.Type.Kind() == reflect.Ptr && value.Field(i).IsNil() {
|
||||
continue
|
||||
}
|
||||
if value.Field(i).IsZero() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// If the json tag is not empty, use it as the key
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user