Documentation
¶
Index ¶
- Variables
- func AllOfList[T any](l *list.List) []T
- func FileLine(fn any) (file string, line int, fnName string)
- func FormatError(err error, format string, args ...any) error
- func FuncName(fn any) string
- func IsBeanInjectionTarget(t reflect.Type) bool
- func IsBeanType(t reflect.Type) bool
- func IsConstructor(t reflect.Type) bool
- func IsErrorType(t reflect.Type) bool
- func IsFuncType(t reflect.Type) bool
- func IsPrimitiveValueType(t reflect.Type) bool
- func IsPropBindingTarget(t reflect.Type) bool
- func ListOf[T any](a ...T) *list.List
- func LocalIPv4() string
- func MD5(str string) string
- func OrderedMapKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K
- func PatchValue(v reflect.Value) reflect.Value
- func PathExists(file string) (bool, error)
- func Ptr[T any](i T) *T
- func ReadDirNames(dirname string) ([]string, error)
- func ReturnNothing(t reflect.Type) bool
- func ReturnOnlyError(t reflect.Type) bool
- func WrapError(err error, format string, args ...any) error
- type FloatType
- type IntType
- type UintType
Constants ¶
This section is empty.
Variables ¶
var ErrForbiddenMethod = errors.New("forbidden method")
ErrForbiddenMethod throws this error when calling a method is prohibited.
var ErrUnimplementedMethod = errors.New("unimplemented method")
ErrUnimplementedMethod throws this error when calling an unimplemented method.
Functions ¶
func FileLine ¶
FileLine returns the file, line number, and function name for a given function. It uses reflection and runtime information to extract these details. 'fn' is expected to be a function or method value.
func FormatError ¶ added in v1.2.4
FormatError formats an error message and returns a new error. If the provided error is non-nil, it appends the formatted message before it.
func IsBeanInjectionTarget ¶ added in v1.2.4
IsBeanInjectionTarget reports whether the provided reflect.Type is a valid target for bean injection.
Valid targets include:
- a bean type itself
- collections (map, slice, array) whose element type is a bean
func IsBeanType ¶ added in v1.1.1
IsBeanType reports whether the provided reflect.Type is considered a "bean" type.
A "bean" type is defined as:
- a channel type
- a function type
- an interface type
- a pointer to a struct type
func IsConstructor ¶
IsConstructor reports whether the provided function type is considered a constructor by convention.
A constructor is defined as a function that returns:
- one non-error value, or
- two values where the second value is an error.
Examples of valid constructor signatures:
func() *MyStruct func(cfg Config) (*MyStruct, error)
Examples of invalid constructor signatures:
func() // returns nothing func() error // returns only an error func() (*A, *B, error) // returns more than two values
func IsErrorType ¶
IsErrorType reports whether the provided reflect.Type represents the built-in error type or a type that implements the error interface.
func IsFuncType ¶
IsFuncType reports whether the provided reflect.Type represents a function.
func IsPrimitiveValueType ¶
IsPrimitiveValueType reports whether the provided reflect.Type represents a primitive value type such as an integer, unsigned integer, float, string, or boolean.
func IsPropBindingTarget ¶ added in v1.2.4
IsPropBindingTarget reports whether the provided reflect.Type is a valid target for property binding.
Valid types include:
- primitive value types
- struct types
- collections (map, slice, array) whose element type is a primitive value or a struct
func LocalIPv4 ¶
func LocalIPv4() string
LocalIPv4 retrieves the first non-loopback IPv4 address of the local machine. The result is cached after the first call using sync.Once.
func MD5 ¶
MD5 computes the MD5 checksum of the given string and returns it as a lowercase hexadecimal string.
func OrderedMapKeys ¶ added in v1.2.4
OrderedMapKeys returns the sorted keys of a map whose key type is ordered. This provides a deterministic order for iteration over maps.
func PatchValue ¶
PatchValue modifies an unexported field to make it assignable by modifying the internal flag. It takes a reflect.Value and returns the patched value that can be written to. This is typically used to manipulate unexported fields in struct types.
func PathExists ¶ added in v1.2.4
PathExists checks whether the specified file or directory exists.
func ReadDirNames ¶
ReadDirNames reads all entry names in the given directory.
func ReturnNothing ¶
ReturnNothing reports whether the provided function type returns no values. It is useful when analyzing function signatures using reflection.
func ReturnOnlyError ¶
ReturnOnlyError reports whether the provided function type returns exactly one value and that value is an error.
Types ¶
type FloatType ¶ added in v1.2.4
FloatType is a generic constraint that represents floating-point types: float32 and float64.