优化异常实例化
This commit is contained in:
		
							
								
								
									
										5
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										5
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@ -4,7 +4,10 @@
 | 
				
			|||||||
    <option name="autoReloadType" value="ALL" />
 | 
					    <option name="autoReloadType" value="ALL" />
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="ChangeListManager">
 | 
					  <component name="ChangeListManager">
 | 
				
			||||||
    <list default="true" id="0c7a619f-b520-4d41-ab0d-cfa1799d3cdf" name="Changes" comment="" />
 | 
					    <list default="true" id="0c7a619f-b520-4d41-ab0d-cfa1799d3cdf" name="Changes" comment="">
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/abstrace.go" beforeDir="false" afterPath="$PROJECT_DIR$/abstrace.go" afterDir="false" />
 | 
				
			||||||
 | 
					      <change beforePath="$PROJECT_DIR$/exception.go" beforeDir="false" afterPath="$PROJECT_DIR$/exception.go" afterDir="false" />
 | 
				
			||||||
 | 
					    </list>
 | 
				
			||||||
    <option name="SHOW_DIALOG" value="false" />
 | 
					    <option name="SHOW_DIALOG" value="false" />
 | 
				
			||||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
					    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
				
			||||||
    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
 | 
					    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ type IException interface {
 | 
				
			|||||||
	// GetMessage *获取错误信息
 | 
						// GetMessage *获取错误信息
 | 
				
			||||||
	GetMessage() string
 | 
						GetMessage() string
 | 
				
			||||||
	// GetData 获取异常时的返回数据
 | 
						// GetData 获取异常时的返回数据
 | 
				
			||||||
	GetData() map[string]interface{}
 | 
						GetData() interface{}
 | 
				
			||||||
	// GetHttpCode *获取当前异常要返回的http状态码, 不设置则 默认 200
 | 
						// GetHttpCode *获取当前异常要返回的http状态码, 不设置则 默认 200
 | 
				
			||||||
	GetHttpCode() int
 | 
						GetHttpCode() int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								exception.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								exception.go
									
									
									
									
									
								
							@ -46,7 +46,7 @@ func (e *Exception) GetHttpCode() int {
 | 
				
			|||||||
// Author : go_developer@163.com<白茶清欢>
 | 
					// Author : go_developer@163.com<白茶清欢>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Date : 21:22 2022/6/25
 | 
					// Date : 21:22 2022/6/25
 | 
				
			||||||
func NewWithCode(code interface{}) *Exception {
 | 
					func NewWithCode(code interface{}) IException {
 | 
				
			||||||
	return New(code, defaultHttpCode, nil)
 | 
						return New(code, defaultHttpCode, nil)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -55,7 +55,7 @@ func NewWithCode(code interface{}) *Exception {
 | 
				
			|||||||
// Author : go_developer@163.com<白茶清欢>
 | 
					// Author : go_developer@163.com<白茶清欢>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Date : 21:25 2022/6/25
 | 
					// 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)
 | 
						return New(code, httpCode, nil)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,7 +64,7 @@ func NewWithCodeAndHttpCode(code interface{}, httpCode int) *Exception {
 | 
				
			|||||||
// Author : go_developer@163.com<白茶清欢>
 | 
					// Author : go_developer@163.com<白茶清欢>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Date : 21:28 2022/6/25
 | 
					// 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)
 | 
						return New(code, defaultHttpCode, data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -73,7 +73,7 @@ func NewWithCodeAndData(code interface{}, data interface{}) *Exception {
 | 
				
			|||||||
// Author : go_developer@163.com<白茶清欢>
 | 
					// Author : go_developer@163.com<白茶清欢>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Date : 21:28 2022/6/25
 | 
					// 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 {
 | 
						if nil == data {
 | 
				
			||||||
		// 保证数据结构的一致性, 同时避免后续使用出现空指针
 | 
							// 保证数据结构的一致性, 同时避免后续使用出现空指针
 | 
				
			||||||
		data = map[string]interface{}{}
 | 
							data = map[string]interface{}{}
 | 
				
			||||||
@ -91,7 +91,7 @@ func New(code interface{}, httpCode int, data interface{}) *Exception {
 | 
				
			|||||||
// Author : go_developer@163.com<白茶清欢>
 | 
					// Author : go_developer@163.com<白茶清欢>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Date : 21:36 2022/6/25
 | 
					// Date : 21:36 2022/6/25
 | 
				
			||||||
func NewFromError(code interface{}, err error) *Exception {
 | 
					func NewFromError(code interface{}, err error) IException {
 | 
				
			||||||
	if nil == err {
 | 
						if nil == err {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -126,6 +126,6 @@ func IsSuccess(e *Exception) bool {
 | 
				
			|||||||
// Author : go_developer@163.com<白茶清欢>
 | 
					// Author : go_developer@163.com<白茶清欢>
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// Date : 22:35 2022/6/25
 | 
					// Date : 22:35 2022/6/25
 | 
				
			||||||
func NewSuccess(data interface{}) *Exception {
 | 
					func NewSuccess(data interface{}) IException {
 | 
				
			||||||
	return New(defaultSuccessCode, defaultHttpCode, data)
 | 
						return New(defaultSuccessCode, defaultHttpCode, data)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user