reflect

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIfZero

func AssertIfZero(elem any, msg string)

AssertIfZero panics if the element is zero.

Parameters:

  • elem: The element to check.
  • msg: The message to show if the element is zero.

The panic message is the string msg.

func IsEmpty

func IsEmpty(elem any) bool

IsEmpty returns true if the element is empty.

Parameters:

  • elem: The element to check.

Returns:

  • bool: True if the element is empty, false otherwise.

func TypeOf

func TypeOf(value any) string

TypeOf returns the type of the value as a string.

Parameters:

  • value: The value to get the type of.

Returns:

  • string: The type of the value.

Types

type ErrEmpty

type ErrEmpty[T any] struct {
	// Value is the value that caused the error.
	Value T
}

ErrEmpty represents an error when a value is empty.

func NewErrEmpty

func NewErrEmpty[T any](value T) *ErrEmpty[T]

NewErrEmpty creates a new ErrEmpty error.

Parameters:

  • value: The value that caused the error.

Returns:

  • *ErrEmpty: A pointer to the newly created ErrEmpty.

func (*ErrEmpty[T]) Error

func (e *ErrEmpty[T]) Error() string

Error implements the error interface.

Message: "<type> must not be empty"

type ErrInvalidCall

type ErrInvalidCall struct {
	// FnName is the name of the function.
	FnName string

	// Signature is the Signature of the function.
	Signature reflect.Type

	// Reason is the Reason for the failure.
	Reason error
}

ErrInvalidCall represents an error that occurs when a function is not called correctly.

func NewErrInvalidCall

func NewErrInvalidCall(functionName string, function any, reason error) *ErrInvalidCall

NewErrInvalidCall creates a new ErrInvalidCall.

Parameters:

  • functionName: The name of the function.
  • function: The function that failed.
  • reason: The reason for the failure.

Returns:

  • *ErrInvalidCall: A pointer to the new ErrInvalidCall.

func (*ErrInvalidCall) ChangeReason

func (e *ErrInvalidCall) ChangeReason(reason error)

ChangeReason implements the Unwrapper interface.

func (*ErrInvalidCall) Error

func (e *ErrInvalidCall) Error() string

Error implements the Unwrapper interface.

Message: "call to {function}({signature}) failed: {reason}".

However, if the reason is nil, the message is "call to {function}({signature}) failed" instead.

func (*ErrInvalidCall) Unwrap

func (e *ErrInvalidCall) Unwrap() error

Unwrap implements the Unwrapper interface.

type FunctionCall

type FunctionCall struct {
	// Call is the string representation of the function call.
	Call string

	// Dependencies are the dependencies of the function call.
	Dependencies []string
}

FunctionCall represents a function call.

func GetStringOf

func GetStringOf(type_name string, elem any, custom map[string][]string) FunctionCall

GetStringOf returns the string function call for the given element.

Parameters:

  • type_name: The name of the type.
  • elem: The element to get the string of.
  • custom: The custom strings to use. Empty values are ignored.

Returns:

  • FunctionCall: The function call.

func NewFunctionCall

func NewFunctionCall(call string, dependencies []string) FunctionCall

Jump to

Keyboard shortcuts

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