util

package
v1.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 12, 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.

View Source
var WrapFormat = func(err error, fileline string, msg string) error {
	if err == nil {
		return fmt.Errorf("%s %s", fileline, msg)
	}
	return fmt.Errorf("%s %s; %w", fileline, msg, err)
}

Functions

func Error

func Error(fileline string, text string) error

Error returns an error with the file and line. The file and line may be calculated at the compile time in the future.

func Errorf

func Errorf(fileline string, format string, a ...interface{}) error

Errorf returns an error with the file and line. The file and line may be calculated at the compile time in the future.

func FileLine

func FileLine(fn interface{}) (file string, line int, fnName string)

FileLine returns a function's name, file name and line number.

func FlattenMap

func FlattenMap(m map[string]interface{}) map[string]string

FlattenMap can expand the nested array, slice and map.

func FlattenValue

func FlattenValue(key string, val interface{}, result map[string]string)

FlattenValue can expand the nested array, slice and map.

func HasReceiver

func HasReceiver(t reflect.Type, receiver reflect.Value) bool

HasReceiver returns whether the function has a receiver.

func Indirect

func Indirect(t reflect.Type) reflect.Type

Indirect returns its element type when t is a pointer type.

func IsBeanReceiver

func IsBeanReceiver(t reflect.Type) bool

IsBeanReceiver returns whether the `t` is a bean receiver, a bean receiver can be a bean, a map or slice whose elements are beans.

func IsBeanType

func IsBeanType(t reflect.Type) bool

IsBeanType returns whether `t` is a bean type.

func IsConstructor

func IsConstructor(t reflect.Type) bool

IsConstructor returns whether `t` is a constructor type. What is a constructor? It should be a function first, has any number of inputs and supports the option pattern input, has one or two outputs and the second output should be an error.

func IsErrorType

func IsErrorType(t reflect.Type) bool

IsErrorType returns whether `t` is error type.

func IsFuncType

func IsFuncType(t reflect.Type) bool

IsFuncType returns whether `t` is func type.

func IsPrimitiveValueType

func IsPrimitiveValueType(t reflect.Type) bool

IsPrimitiveValueType returns whether `t` is the primitive value type which only is int, unit, float, bool, string and complex.

func IsStructPtr

func IsStructPtr(t reflect.Type) bool

IsStructPtr returns whether it is the pointer type of structure.

func IsValueType

func IsValueType(t reflect.Type) bool

IsValueType returns whether the input type is the primitive value type and their composite type including array, slice, map and struct, such as []int, [3]string, []string, map[int]int, map[string]string, etc.

func PatchValue

func PatchValue(v reflect.Value) reflect.Value

PatchValue makes an unexported field can be assignable.

func ReturnNothing

func ReturnNothing(t reflect.Type) bool

ReturnNothing returns whether the function has no return value.

func ReturnOnlyError

func ReturnOnlyError(t reflect.Type) bool

ReturnOnlyError returns whether the function returns only error value.

func TypeName

func TypeName(i interface{}) string

TypeName returns a fully qualified name consisting of package path and type name.

func Wrap

func Wrap(err error, fileline string, text string) error

Wrap returns an error with the file and line. The file and line may be calculated at the compile time in the future.

func Wrapf

func Wrapf(err error, fileline string, format string, a ...interface{}) error

Wrapf returns an error with the file and line. The file and line may be calculated at the compile time in the future.

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