变更 interface{} => any
This commit is contained in:
@ -13,8 +13,8 @@ package try
|
||||
//
|
||||
// Date : 11:26 2023/7/20
|
||||
type ICatchHandler interface {
|
||||
Catch(errCode string, handler func(errCode string, data map[string]interface{})) ICatchHandler
|
||||
CatchAll(handler func(errCode string, data map[string]interface{})) IFinalHandler
|
||||
Catch(errCode string, handler func(errCode string, data map[string]any)) ICatchHandler
|
||||
CatchAll(handler func(errCode string, data map[string]any)) IFinalHandler
|
||||
IFinalHandler
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ type ICatchHandler interface {
|
||||
//
|
||||
// Date : 11:27 2023/7/20
|
||||
type IFinalHandler interface {
|
||||
Finally(data map[string]interface{}, handlers ...func(data map[string]interface{}))
|
||||
Finally(data map[string]any, handlers ...func(data map[string]any))
|
||||
}
|
||||
|
||||
// ILogicFunction 逻辑函数约束
|
||||
|
@ -15,7 +15,7 @@ package try
|
||||
type DefaultCatchHandler struct {
|
||||
hasDeal bool // 异常是否已被处理
|
||||
errCode string
|
||||
data map[string]interface{}
|
||||
data map[string]any
|
||||
}
|
||||
|
||||
// hasDealError 判断异常是否已经被处理
|
||||
@ -38,7 +38,7 @@ func (d *DefaultCatchHandler) hasDealError() bool {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:19 2023/7/20
|
||||
func (d *DefaultCatchHandler) Catch(errCode string, handler func(errCode string, data map[string]interface{})) ICatchHandler {
|
||||
func (d *DefaultCatchHandler) Catch(errCode string, handler func(errCode string, data map[string]any)) ICatchHandler {
|
||||
if d.hasDealError() {
|
||||
return d
|
||||
}
|
||||
@ -61,7 +61,7 @@ func (d *DefaultCatchHandler) Catch(errCode string, handler func(errCode string,
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:47 2023/7/20
|
||||
func (d *DefaultCatchHandler) CatchAll(handler func(errCode string, data map[string]interface{})) IFinalHandler {
|
||||
func (d *DefaultCatchHandler) CatchAll(handler func(errCode string, data map[string]any)) IFinalHandler {
|
||||
if d.hasDealError() {
|
||||
return d
|
||||
}
|
||||
@ -80,9 +80,9 @@ func (d *DefaultCatchHandler) CatchAll(handler func(errCode string, data map[str
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:48 2023/7/20
|
||||
func (d *DefaultCatchHandler) Finally(data map[string]interface{}, handlers ...func(data map[string]interface{})) {
|
||||
func (d *DefaultCatchHandler) Finally(data map[string]any, handlers ...func(data map[string]any)) {
|
||||
if data == nil {
|
||||
data = map[string]interface{}{}
|
||||
data = map[string]any{}
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); nil != r {
|
||||
|
@ -13,7 +13,7 @@ package try
|
||||
//
|
||||
// Date : 11:30 2023/7/20
|
||||
type LogicFuncInput struct {
|
||||
Parameter map[string]interface{}
|
||||
Parameter map[string]any
|
||||
}
|
||||
|
||||
// LogicFuncOutput ...
|
||||
@ -22,8 +22,8 @@ type LogicFuncInput struct {
|
||||
//
|
||||
// Date : 11:30 2023/7/20
|
||||
type LogicFuncOutput struct {
|
||||
ErrCode string // 错误标识码
|
||||
Data map[string]interface{} // 错误时返回的数据
|
||||
ErrCode string // 错误标识码
|
||||
Data map[string]any // 错误时返回的数据
|
||||
}
|
||||
|
||||
// NewLogicFuncOutput 获取逻辑函数输出数据
|
||||
@ -31,9 +31,9 @@ type LogicFuncOutput struct {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 11:33 2023/7/20
|
||||
func NewLogicFuncOutput(code string, data map[string]interface{}) LogicFuncOutput {
|
||||
func NewLogicFuncOutput(code string, data map[string]any) LogicFuncOutput {
|
||||
if data == nil {
|
||||
data = map[string]interface{}{}
|
||||
data = map[string]any{}
|
||||
}
|
||||
r := LogicFuncOutput{
|
||||
ErrCode: code,
|
||||
|
@ -22,14 +22,14 @@ func Try(fn ILogicFunction, input *LogicFuncInput) ICatchHandler {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
catchHandler.errCode = LogicFuncPanic
|
||||
catchHandler.data = map[string]interface{}{
|
||||
catchHandler.data = map[string]any{
|
||||
"message": r.(error).Error(),
|
||||
}
|
||||
}
|
||||
}()
|
||||
if nil == input {
|
||||
input = &LogicFuncInput{
|
||||
Parameter: map[string]interface{}{},
|
||||
Parameter: map[string]any{},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user