2023-11-29 11:59:54 +08:00
|
|
|
// Package try ...
|
|
|
|
//
|
|
|
|
// Description : try ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2023-07-20 11:36
|
|
|
|
package try
|
|
|
|
|
|
|
|
// Try try入口函数
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:37 2023/7/20
|
|
|
|
func Try(fn ILogicFunction, input *LogicFuncInput) ICatchHandler {
|
|
|
|
catchHandler := &DefaultCatchHandler{}
|
|
|
|
if nil == fn {
|
|
|
|
// 逻辑函数空指针
|
|
|
|
catchHandler.errCode = NilLogicFunc
|
|
|
|
return catchHandler
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
catchHandler.errCode = LogicFuncPanic
|
2024-06-08 20:06:35 +08:00
|
|
|
catchHandler.data = map[string]any{
|
2023-11-29 11:59:54 +08:00
|
|
|
"message": r.(error).Error(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
if nil == input {
|
|
|
|
input = &LogicFuncInput{
|
2024-06-08 20:06:35 +08:00
|
|
|
Parameter: map[string]any{},
|
2023-11-29 11:59:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result := fn(input)
|
|
|
|
catchHandler.errCode = result.ErrCode
|
|
|
|
catchHandler.data = result.Data
|
|
|
|
|
|
|
|
return catchHandler
|
|
|
|
}
|