util

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbiddenMethod = errors.New("forbidden method")

ErrForbiddenMethod throws this error when calling a method is prohibited.

View Source
var ErrUnimplementedMethod = errors.New("unimplemented method")

ErrUnimplementedMethod throws this error when calling an unimplemented method.

Functions

func AllOfList

func AllOfList[T any](l *list.List) []T

AllOfList returns a slice of all items in the given list.

func FileLine

func FileLine(fn any) (file string, line int, fnName string)

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 FlattenMap

func FlattenMap(m map[string]any) map[string]string

FlattenMap flattens a nested map, array, or slice into a single-level map with string keys and string values. It recursively processes each element of the input map and adds its flattened representation to the result map.

func FlattenValue

func FlattenValue(key string, val any, result map[string]string)

FlattenValue flattens a single value (which can be a map, array, slice, or other types) into the result map.

func FuncName

func FuncName(fn any) string

FuncName returns the function name for a given function.

func IsBeanInjectionTarget

func IsBeanInjectionTarget(t reflect.Type) bool

IsBeanInjectionTarget returns true if the provided type t is a valid target for bean injection. This includes maps, slices, arrays, or any other bean type (including pointers to structs).

func IsBeanType

func IsBeanType(t reflect.Type) bool

IsBeanType returns true if the provided type t is considered a "bean" type. A "bean" type includes a channel, function, interface, or a pointer to a struct.

func IsConstructor

func IsConstructor(t reflect.Type) bool

IsConstructor returns true if the provided function type t is a constructor. A constructor is defined as a function that returns one or two values. If it returns two values, the second value must be an error.

func IsErrorType

func IsErrorType(t reflect.Type) bool

IsErrorType returns true if the provided type t is an error type, either directly (error) or via an implementation (i.e., implements the error interface).

func IsFuncType

func IsFuncType(t reflect.Type) bool

IsFuncType returns true if the provided type t is a function type.

func IsPrimitiveValueType

func IsPrimitiveValueType(t reflect.Type) bool

IsPrimitiveValueType returns true if the provided type t is a primitive value type, such as int, uint, float, bool, or string.

func IsPropBindingTarget

func IsPropBindingTarget(t reflect.Type) bool

IsPropBindingTarget returns true if the provided type t is a valid target for property binding. This includes primitive value types or composite types (such as array, slice, map, or struct) where the elements are primitive value types.

func ListOf

func ListOf[T any](a ...T) *list.List

ListOf creates a list of the given items.

func MapKeys

func MapKeys[M ~map[K]V, K comparable, V any](m M) []K

MapKeys returns the keys of the map m.

func OrderedMapKeys

func OrderedMapKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K

OrderedMapKeys returns the keys of the map m in sorted order.

func PatchValue

func PatchValue(v reflect.Value) reflect.Value

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 ReturnNothing

func ReturnNothing(t reflect.Type) bool

ReturnNothing returns true if the provided function type t has no return values.

func ReturnOnlyError

func ReturnOnlyError(t reflect.Type) bool

ReturnOnlyError returns true if the provided function type t returns only one value, and that value is an error.

Types

This section is empty.

Directories

Path Synopsis
Package goutil provides a safe way to execute goroutines with built-in panic recovery.
Package goutil provides a safe way to execute goroutines with built-in panic recovery.
Package sysconf provides a unified configuration container for the Go programming language.
Package sysconf provides a unified configuration container for the Go programming language.
Package syslog provides simplified logging utilities for tracking the execution flow of the go-spring framework.
Package syslog provides simplified logging utilities for tracking the execution flow of the go-spring framework.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL