wrapper/try/try.go

42 lines
834 B
Go

// 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
catchHandler.data = map[string]any{
"message": r.(error).Error(),
}
}
}()
if nil == input {
input = &LogicFuncInput{
Parameter: map[string]any{},
}
}
result := fn(input)
catchHandler.errCode = result.ErrCode
catchHandler.data = result.Data
return catchHandler
}