Documentation
¶
Overview ¶
Copyright 2025 atframework
Copyright 2025 atframework ¶
Copyright 2025 atframework Package libatframe_utils_lang_utility provides utility functions for language-level operations.
Copyright 2025 atframework Package libatframe_utils_lang_utility provides utility functions for language-level operations.
Index ¶
- func AssignValue(pt reflect.Type, p string) (reflect.Value, error)
- func BytestoString(b []byte) string
- func FormatValues(values []reflect.Value) []string
- func GetDataPointerOfInterface(d interface{}) unsafe.Pointer
- func IsDeduplicate[T comparable](elem []T) bool
- func IsDeduplicateWithOut[T comparable](elem []T, witchOut T) bool
- func IsExist[T comparable](elem []T, target T) bool
- func IsNil(i interface{}) bool
- func StringtoBytes(s string) []byte
- type AtomicInterface
- type TypeID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignValue ¶
不支持 Map of Structs ,Nested Maps.
func BytestoString ¶
func FormatValues ¶
func IsDeduplicate ¶
func IsDeduplicate[T comparable](elem []T) bool
func IsDeduplicateWithOut ¶
func IsDeduplicateWithOut[T comparable](elem []T, witchOut T) bool
func IsExist ¶
func IsExist[T comparable](elem []T, target T) bool
func IsNil ¶
func IsNil(i interface{}) bool
IsNil reports whether the interface value i is nil.
Unlike a simple "i == nil" comparison, this function correctly handles the case where an interface contains a nil pointer (e.g., a nil *T assigned to an interface{} is not equal to nil, but IsNil returns true).
This implementation uses unsafe pointer manipulation for maximum performance, completely avoiding reflection overhead. It directly accesses the interface's internal structure and the runtime type information.
Supported nil-able types: pointer, slice, map, channel, function, interface, unsafe.Pointer. For non-nil-able types (int, string, struct, etc.), returns false.
func StringtoBytes ¶
//////////////// 转换产物不可写 ////////////////////////
Types ¶
type AtomicInterface ¶
type AtomicInterface[T comparable] struct { // contains filtered or unexported fields }
AtomicInterface is a lock-free holder dedicated to interface values, providing nil-safe helpers.
func NewAtomicInterface ¶
func NewAtomicInterface[T comparable](initial T) *AtomicInterface[T]
NewAtomicInterface creates an AtomicInterface initialized with the provided value. The initial value may be nil.
func (*AtomicInterface[T]) CompareAndSwap ¶
func (av *AtomicInterface[T]) CompareAndSwap(oldV, newV T) bool
CompareAndSwap atomically replaces the stored value with newV when the current value matches oldV. It returns true on success.
func (*AtomicInterface[T]) Load ¶
func (av *AtomicInterface[T]) Load() T
Load returns the stored value or the zero value if nothing has been stored yet.
func (*AtomicInterface[T]) Store ¶
func (av *AtomicInterface[T]) Store(v T)
Store saves v atomically. It accepts typed nil values.
func (*AtomicInterface[T]) Swap ¶
func (av *AtomicInterface[T]) Swap(newV T) T
Swap atomically stores newV and returns the previously stored value.
type TypeID ¶
type TypeID uintptr
TypeID is a unique identifier for a Go type. It can be used as a map key and is comparable. This is a high-performance alternative to reflect.Type when you only need type identity comparison, not the full reflection capabilities.
TypeID is derived from the internal runtime type pointer, which is guaranteed to be unique and stable for each distinct type within a program.
func GetTypeID ¶
func GetTypeID(i interface{}) TypeID
GetTypeID returns the TypeID for the given interface value. The TypeID is based on the dynamic type of the value, not the static type.
Example:
var x int = 42 var y int = 100 var z string = "hello" GetTypeID(x) == GetTypeID(y) // true: same type (int) GetTypeID(x) == GetTypeID(z) // false: different types
func GetTypeIDOf ¶
GetTypeIDOf returns a unique TypeID for type T that works for ALL types, including interface types. This is achieved by using the pointer type *T internally, which always has valid type information even for nil values.
The returned TypeID uniquely identifies the type T. Different types always have different TypeIDs, and the same type always has the same TypeID.
Example:
id := GetTypeIDOf[int]() // works for primitive types id := GetTypeIDOf[MyStruct]() // works for struct types id := GetTypeIDOf[io.Reader]() // works for interface types
func GetTypeIDOfPointer ¶
GetTypeIDOfPointer returns the TypeID for pointer type *T. This is equivalent to GetTypeIDOf[*T]() but more convenient.
Example:
id := GetTypeIDOfPointer[MyStruct]() // returns TypeID for *MyStruct // equivalent to: GetTypeIDOf[*MyStruct]()