Documentation ¶
Overview ¶
Package util is a generated GoMock package.
Index ¶
- Variables
- func Contract(filename string, maxLength int) string
- func CopyBean(src interface{}, dest interface{}) error
- func Error(fileline string, text string) error
- func Errorf(fileline string, format string, a ...interface{}) error
- func FileLine(fn interface{}) (file string, line int, fnName string)
- func HasReceiver(t reflect.Type, receiver reflect.Type) bool
- func Indirect(t reflect.Type) reflect.Type
- func IsBeanReceiver(t reflect.Type) bool
- func IsBeanType(t reflect.Type) bool
- func IsConstructor(t reflect.Type) bool
- func IsContextType(t reflect.Type) bool
- func IsErrorType(t reflect.Type) bool
- func IsFuncType(t reflect.Type) bool
- func IsPrimitiveValueType(t reflect.Type) bool
- func IsStructPtr(t reflect.Type) bool
- func IsValidConverter(t reflect.Type) bool
- func IsValueType(t reflect.Type) bool
- func LocalIPv4() string
- func MD5(str string) string
- func MustTestMode()
- func NewList(v ...interface{}) *list.List
- func PatchValue(v reflect.Value) reflect.Value
- func ReadDirNames(dirname string) ([]string, error)
- func ReturnNothing(t reflect.Type) bool
- func ReturnOnlyError(t reflect.Type) bool
- func SafeCloseChan(ch chan struct{})
- func SearchList(l *list.List, v interface{}) *list.Element
- func T(a ...interface{}) []interface{}
- func TripleSort(sorting *list.List, fn GetBeforeItems) *list.List
- func TypeName(i interface{}) string
- func Wrap(err error, fileline string, text string) error
- func Wrapf(err error, fileline string, format string, a ...interface{}) error
- type BeanDefinition
- type BeanSelector
- type Converter
- type GetBeforeItems
- type MockBeanDefinition
- func (m *MockBeanDefinition) BeanName() string
- func (m *MockBeanDefinition) Created() bool
- func (m *MockBeanDefinition) EXPECT() *MockBeanDefinitionMockRecorder
- func (m *MockBeanDefinition) ID() string
- func (m *MockBeanDefinition) Interface() interface{}
- func (m *MockBeanDefinition) Type() reflect.Type
- func (m *MockBeanDefinition) TypeName() string
- func (m *MockBeanDefinition) Value() reflect.Value
- func (m *MockBeanDefinition) Wired() bool
- type MockBeanDefinitionMockRecorder
- func (mr *MockBeanDefinitionMockRecorder) BeanName() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) Created() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) ID() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) Interface() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) Type() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) TypeName() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) Value() *gomock.Call
- func (mr *MockBeanDefinitionMockRecorder) Wired() *gomock.Call
- type MockBeanSelector
- type MockBeanSelectorMockRecorder
- type MockConverter
- type MockConverterMockRecorder
- type NoCopy
- type PanicCond
Constants ¶
This section is empty.
Variables ¶
var ForbiddenMethod = errors.New("forbidden method")
ForbiddenMethod 如果某个方法禁止被调用则可以抛出此错误。
var UnimplementedMethod = errors.New("unimplemented method")
UnimplementedMethod 如果某个方法未实现则可以抛出此错误。
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 CopyBean ¶
func CopyBean(src interface{}, dest interface{}) error
CopyBean 使用 JSON 序列化的方式进行拷贝,支持匿名字段,支持类型转换。
func HasReceiver ¶
HasReceiver 函数是否具有接收者。
func IsBeanReceiver ¶ added in v1.1.1
IsBeanReceiver 返回是否是合法的 bean receiver 类型。顾名思义,bean receiver 类型就是指可以保存 bean 地址的类型。除了 ptr、interface、chan、func 四种单体类 型可以承载对应的 bean 类型之外,它们的集合类型,即 map、slice、array 类型,也是 合法的 bean receiver 类型。它们应用于以单体方式注册 bean 然后以集合方式收集 bean 的场景。
func IsBeanType ¶ added in v1.1.1
IsBeanType 返回是否是 bean 类型。在 go-spring 里,变量的类型分为三种: bean 类 型、value(值) 类型以及其他类型。如果一个变量赋值给另一个变量后二者指向相同的内存地 址,则称这个变量的类型为 bean 类型,反之则称为 value(值) 类型。根据这个定义,只有 ptr、interface、chan、func 这四种类型是 bean 类型。 可能有人会问,上述四种类型的集合类型如 []interface、map[string]*struct 等也是 bean 类型吗?根据 go-spring 的定义,它们不是合法的 bean 类型,但是它们是合法的 bean receiver 类型。那为什么没有把他们也定义为 bean 类型呢?因为如果是切片类型, 那么可以转换为注册切片的元素同时加上 order 排序,如果是 map 类型,那么很显然可以转 换为依次注册 map 的元素。 另外,ptr 一般指一层指针,因为多层指针在 web 开发中很少用到,甚至应该在纯业务代码中 禁止使用多层指针。
func IsConstructor ¶
IsConstructor 返回以函数形式注册 bean 的函数是否合法。一个合法 的注册函数需要以下条件:入参可以有任意多个,支持一般形式和 Option 形式,返回值只能有一个或者两个,第一个返回值必须是 bean 源,它可以是 结构体等值类型也可以是指针等引用类型,为值类型时内部会自动转换为引用类 型(获取可引用的地址),如果有第二个返回值那么它必须是 error 类型。
func IsContextType ¶
IsContextType t 是否是 context.Context 类型。
func IsPrimitiveValueType ¶
IsPrimitiveValueType returns whether the input type is the primitive value type which only is int, unit, float, bool, string and complex.
func IsValueType ¶
IsValueType returns whether the input type is the value type which is the primitive value type and their one dimensional composite type including array, slice, map and struct, such as [3]string, []string, []int, map[int]int, etc.
func PatchValue ¶
PatchValue makes an unexported field can be assignable.
func ReadDirNames ¶
ReadDirNames reads the directory named by dirname and returns an unsorted list of directory entries.
func SearchList ¶
SearchList 在列表中查询指定元素,存在则返回列表项指针,不存在返回 nil。
func TypeName ¶ added in v1.1.1
func TypeName(i interface{}) string
TypeName 返回原始类型的全限定名,类型的全限定名用于严格区分相同名称的 bean 对象。 类型的全限定名是指包的全路径加上类型名称,例如,gs 包里面的 Container 类型,它的 类型全限定名是 github.com/go-spring/spring-core/gs/gs.Container。因为 go 语言允许在不同的路径下存在名称相同的包,所以有可能出现(简单)类型名称相同、实例名称 相同的但实际上类型不相同的 bean 对象,因此有类型的全限定名这样的概念,用以严格区分 同名的 bean 对象。
Types ¶
type BeanDefinition ¶ added in v1.1.1
type BeanDefinition interface { Type() reflect.Type // 类型 Value() reflect.Value // 值 Interface() interface{} // 源 ID() string // 返回 bean 的 ID BeanName() string // 返回 bean 的名称 TypeName() string // 返回类型的全限定名 Created() bool // 返回是否已创建 Wired() bool // 返回是否已注入 }
BeanDefinition bean 元数据。
type BeanSelector ¶ added in v1.1.1
type BeanSelector interface{}
BeanSelector bean 选择器,可以是 bean ID 字符串,可 以是 reflect.Type 对象,可以是形如 (*error)(nil) 的指针,还可以是 Definition 类型的对象。
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 GetBeforeItems ¶
GetBeforeItems 获取 sorting 中排在 current 前面的元素
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
func (m *MockBeanDefinition) EXPECT() *MockBeanDefinitionMockRecorder
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
func (mr *MockBeanDefinitionMockRecorder) Created() *gomock.Call
Created indicates an expected call of Created.
func (*MockBeanDefinitionMockRecorder) ID ¶ added in v1.1.1
func (mr *MockBeanDefinitionMockRecorder) ID() *gomock.Call
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
func (mr *MockBeanDefinitionMockRecorder) Type() *gomock.Call
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
func (mr *MockBeanDefinitionMockRecorder) Value() *gomock.Call
Value indicates an expected call of Value.
func (*MockBeanDefinitionMockRecorder) Wired ¶ added in v1.1.1
func (mr *MockBeanDefinitionMockRecorder) Wired() *gomock.Call
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
func (m *MockBeanSelector) EXPECT() *MockBeanSelectorMockRecorder
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
func (m *MockConverter) EXPECT() *MockConverterMockRecorder
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 NoCopy ¶
type NoCopy struct{}
NoCopy may be embedded into structs which must not be copied after the first use.
See https://golang.org/issues/8005#issuecomment-190753527 for details.
type PanicCond ¶
type PanicCond struct {
// contains filtered or unexported fields
}
PanicCond 封装触发 panic 的条件。
func NewPanicCond ¶
func NewPanicCond(fn func() interface{}) *PanicCond
NewPanicCond PanicCond 的构造函数。