util

package
v1.2.0-rc Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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

ForbiddenMethod throws this error when calling a method is prohibited.

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

UnimplementedMethod throws this error when calling an unimplemented method.

Functions

func FileLine

func FileLine(fn interface{}) (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]interface{}) 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 interface{}, result map[string]string)

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

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 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 assert provides some useful assertion methods.
Package assert provides some useful assertion methods.

Jump to

Keyboard shortcuts

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