优化异常实例化
This commit is contained in:
12
exception.go
12
exception.go
@ -46,7 +46,7 @@ func (e *Exception) GetHttpCode() int {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:22 2022/6/25
|
||||
func NewWithCode(code interface{}) *Exception {
|
||||
func NewWithCode(code interface{}) IException {
|
||||
return New(code, defaultHttpCode, nil)
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func NewWithCode(code interface{}) *Exception {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:25 2022/6/25
|
||||
func NewWithCodeAndHttpCode(code interface{}, httpCode int) *Exception {
|
||||
func NewWithCodeAndHttpCode(code interface{}, httpCode int) IException {
|
||||
return New(code, httpCode, nil)
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ func NewWithCodeAndHttpCode(code interface{}, httpCode int) *Exception {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:28 2022/6/25
|
||||
func NewWithCodeAndData(code interface{}, data interface{}) *Exception {
|
||||
func NewWithCodeAndData(code interface{}, data interface{}) IException {
|
||||
return New(code, defaultHttpCode, data)
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ func NewWithCodeAndData(code interface{}, data interface{}) *Exception {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:28 2022/6/25
|
||||
func New(code interface{}, httpCode int, data interface{}) *Exception {
|
||||
func New(code interface{}, httpCode int, data interface{}) IException {
|
||||
if nil == data {
|
||||
// 保证数据结构的一致性, 同时避免后续使用出现空指针
|
||||
data = map[string]interface{}{}
|
||||
@ -91,7 +91,7 @@ func New(code interface{}, httpCode int, data interface{}) *Exception {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:36 2022/6/25
|
||||
func NewFromError(code interface{}, err error) *Exception {
|
||||
func NewFromError(code interface{}, err error) IException {
|
||||
if nil == err {
|
||||
return nil
|
||||
}
|
||||
@ -126,6 +126,6 @@ func IsSuccess(e *Exception) bool {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:35 2022/6/25
|
||||
func NewSuccess(data interface{}) *Exception {
|
||||
func NewSuccess(data interface{}) IException {
|
||||
return New(defaultSuccessCode, defaultHttpCode, data)
|
||||
}
|
||||
|
Reference in New Issue
Block a user