代码拉取完成,页面将自动刷新
// Package di provides a reflection-based dependency injection toolkit.
package di
import (
"fmt"
"reflect"
)
var (
typeError = reflect.TypeOf((*error)(nil)).Elem()
typeClean = reflect.TypeOf(Clean(nil))
)
// Creator represents a creator function.
type Creator func(reflect.Type) (reflect.Value, error)
// Closer is the interface that wraps the basic Close method.
type Closer interface {
Close() error
}
// Clean represents a clean function.
type Clean func() error
// Do does the clean up.
func (a Clean) Do() (err error) {
defer Catch("", &err)
return a()
}
// Catch catches the panic and format the error.
func Catch(format string, err *error) {
if x := recover(); x != nil {
if e, ok := x.(error); ok {
*err = e
} else {
*err = fmt.Errorf("%v", x)
}
}
if format != "" && *err != nil {
*err = fmt.Errorf(format, *err)
}
}
func typeAs(rt reflect.Type, itype any) (reflect.Type, error) {
if itype == nil {
return rt, nil
}
rit := reflect.TypeOf(itype)
if rit.Kind() != reflect.Pointer {
return nil, fmt.Errorf("not pointer to interface: %v", rit)
}
rit = rit.Elem()
if rit.Kind() != reflect.Interface {
return nil, fmt.Errorf("not interface: %v", rit)
}
if !rt.Implements(rit) {
return nil, fmt.Errorf("%v not implement %v", rt, rit)
}
return rit, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。