util

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 13 Imported by: 21

Documentation

Overview

Package util is a generated GoMock package.

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, format string, a ...interface{}) error {
	if err == nil {
		if format != "" {
			return fmt.Errorf(fileline+" "+format, a...)
		}
		return errors.New(fileline + " " + fmt.Sprint(a...))
	}
	if format == "" {
		return fmt.Errorf("%s %s; %w", fileline, fmt.Sprint(a...), err)
	}
	return fmt.Errorf("%s %s; %w", fileline, fmt.Sprintf(format, a...), err)
}

Functions

func Contract

func Contract(filename string, maxLength int) string

Contract contracts `filename` and replace the excessive part using `...`.

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 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 added in v1.1.1

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 added in v1.1.1

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 IsContextType

func IsContextType(t reflect.Type) bool

IsContextType returns whether `t` is context.Context type.

func IsConverter added in v1.1.3

func IsConverter(t reflect.Type) bool

IsConverter returns whether `t` is a converter type.

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 LocalIPv4

func LocalIPv4() string

LocalIPv4 returns the IPv4 address of the local computer.

func MD5

func MD5(str string) string

MD5 returns the MD5 checksum in hexadecimal encoding of the src.

func PatchValue

func PatchValue(v reflect.Value) reflect.Value

PatchValue makes an unexported field can be assignable.

func ReadDirNames

func ReadDirNames(dirname string) ([]string, error)

ReadDirNames reads the directory named by dirname and returns an unsorted list of directory entries.

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 SafeCloseChan

func SafeCloseChan(ch chan struct{})

SafeCloseChan closes the channel safely.

func TypeName added in v1.1.1

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

type BeanDefinition added in v1.1.1

type BeanDefinition interface {
	Type() reflect.Type
	Value() reflect.Value
	Interface() interface{}
	ID() string
	BeanName() string
	TypeName() string
	Created() bool
	Wired() bool
}

A BeanDefinition describes a bean whose lifecycle is managed by IoC container.

type BeanSelector added in v1.1.1

type BeanSelector interface{}

A BeanSelector can be the ID of a bean, a `reflect.Type`, a pointer such as `(*error)(nil)`, or a BeanDefinition value.

type Converter

type Converter interface{}

Converter converts string value into user-defined value. It should be function type, and its prototype is func(string)(type,error).

type MockBeanDefinition added in v1.1.1

type MockBeanDefinition struct {
	// contains filtered or unexported fields
}

MockBeanDefinition is a mock of BeanDefinition interface.

func NewMockBeanDefinition added in v1.1.1

func NewMockBeanDefinition(ctrl *gomock.Controller) *MockBeanDefinition

NewMockBeanDefinition creates a new mock instance.

func (*MockBeanDefinition) BeanName added in v1.1.1

func (m *MockBeanDefinition) BeanName() string

BeanName mocks base method.

func (*MockBeanDefinition) Created added in v1.1.1

func (m *MockBeanDefinition) Created() bool

Created mocks base method.

func (*MockBeanDefinition) EXPECT added in v1.1.1

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBeanDefinition) ID added in v1.1.1

func (m *MockBeanDefinition) ID() string

ID mocks base method.

func (*MockBeanDefinition) Interface added in v1.1.1

func (m *MockBeanDefinition) Interface() interface{}

Interface mocks base method.

func (*MockBeanDefinition) Type added in v1.1.1

func (m *MockBeanDefinition) Type() reflect.Type

Type mocks base method.

func (*MockBeanDefinition) TypeName added in v1.1.1

func (m *MockBeanDefinition) TypeName() string

TypeName mocks base method.

func (*MockBeanDefinition) Value added in v1.1.1

func (m *MockBeanDefinition) Value() reflect.Value

Value mocks base method.

func (*MockBeanDefinition) Wired added in v1.1.1

func (m *MockBeanDefinition) Wired() bool

Wired mocks base method.

type MockBeanDefinitionMockRecorder added in v1.1.1

type MockBeanDefinitionMockRecorder struct {
	// contains filtered or unexported fields
}

MockBeanDefinitionMockRecorder is the mock recorder for MockBeanDefinition.

func (*MockBeanDefinitionMockRecorder) BeanName added in v1.1.1

func (mr *MockBeanDefinitionMockRecorder) BeanName() *gomock.Call

BeanName indicates an expected call of BeanName.

func (*MockBeanDefinitionMockRecorder) Created added in v1.1.1

Created indicates an expected call of Created.

func (*MockBeanDefinitionMockRecorder) ID added in v1.1.1

ID indicates an expected call of ID.

func (*MockBeanDefinitionMockRecorder) Interface added in v1.1.1

func (mr *MockBeanDefinitionMockRecorder) Interface() *gomock.Call

Interface indicates an expected call of Interface.

func (*MockBeanDefinitionMockRecorder) Type added in v1.1.1

Type indicates an expected call of Type.

func (*MockBeanDefinitionMockRecorder) TypeName added in v1.1.1

func (mr *MockBeanDefinitionMockRecorder) TypeName() *gomock.Call

TypeName indicates an expected call of TypeName.

func (*MockBeanDefinitionMockRecorder) Value added in v1.1.1

Value indicates an expected call of Value.

func (*MockBeanDefinitionMockRecorder) Wired added in v1.1.1

Wired indicates an expected call of Wired.

type MockBeanSelector added in v1.1.1

type MockBeanSelector struct {
	// contains filtered or unexported fields
}

MockBeanSelector is a mock of BeanSelector interface.

func NewMockBeanSelector added in v1.1.1

func NewMockBeanSelector(ctrl *gomock.Controller) *MockBeanSelector

NewMockBeanSelector creates a new mock instance.

func (*MockBeanSelector) EXPECT added in v1.1.1

EXPECT returns an object that allows the caller to indicate expected use.

type MockBeanSelectorMockRecorder added in v1.1.1

type MockBeanSelectorMockRecorder struct {
	// contains filtered or unexported fields
}

MockBeanSelectorMockRecorder is the mock recorder for MockBeanSelector.

type MockConverter added in v1.1.1

type MockConverter struct {
	// contains filtered or unexported fields
}

MockConverter is a mock of Converter interface.

func NewMockConverter added in v1.1.1

func NewMockConverter(ctrl *gomock.Controller) *MockConverter

NewMockConverter creates a new mock instance.

func (*MockConverter) EXPECT added in v1.1.1

EXPECT returns an object that allows the caller to indicate expected use.

type MockConverterMockRecorder added in v1.1.1

type MockConverterMockRecorder struct {
	// contains filtered or unexported fields
}

MockConverterMockRecorder is the mock recorder for MockConverter.

type PanicCond

type PanicCond struct {
	// contains filtered or unexported fields
}

PanicCond panic condition.

func NewPanicCond

func NewPanicCond(fn func() interface{}) *PanicCond

NewPanicCond returns a panic condition.

func Panic

func Panic(err interface{}) *PanicCond

Panic returns a panic condition that throws an error.

func Panicf

func Panicf(format string, a ...interface{}) *PanicCond

Panicf returns a panic condition that throws a formatted error.

func (*PanicCond) When

func (p *PanicCond) When(isPanic bool)

When throws a panic when `isPanic` is true.

Jump to

Keyboard shortcuts

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