Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewInstance ¶
func NewInstance[T any]() T
NewInstance create an instance of the given type T. the main purpose of this function is to create an instance of a type, can handle the type of T is a pointer or not. eg. NewInstance[int] returns 0. eg. NewInstance[*int] returns *0 (will be ptr of 0, not nil!).
func ParseTypeName ¶
ParseTypeName returns the name of the type of the given value. It takes a reflect.Value as input and processes it to determine the underlying type. If the type is a pointer, it dereferences it to get the actual type. (the optimization of this function) eg: ParseTypeName(reflect.ValueOf(&&myStruct{})) returns "myStruct" (not "**myStruct")
If the type is a function, it retrieves the function's name, handling both named and anonymous functions. examples of function paths: [package_path].[receiver_type].[func_name] named function: xxx/utils.ParseTypeName method: xxx/utils.(*MyStruct).Method anonymous function: xxx/utils.TestParseTypeName.func6.1
func PtrOf ¶
func PtrOf[T any](v T) *T
PtrOf returns a pointer of T. useful when you want to get a pointer of a value, in some config, for example. eg. PtrOf[int] returns *int. eg. PtrOf[*int] returns **int.