代码拉取完成,页面将自动刷新
package components
import (
"fmt"
"gitee.com/nuokwan_backend_group/mvc/Base"
"runtime"
"strings"
)
// 自定义
type CustomError struct {
code int
message string
ErrType string
Parent error
}
func NewCustomError(msg string, code int, tyName string, parent ...error) Base.ErrorInstance {
var parentError error
if len(parent) > 0 {
parentError = parent[0]
}
return &CustomError{
code: code,
message: msg,
ErrType: tyName,
Parent: parentError,
}
}
func (c *CustomError) Error() string {
return fmt.Sprintf("message:%s,code: %d", c.Message(), c.Code())
}
func (c *CustomError) Code() int {
return c.code
}
func (c *CustomError) ErrorType() string {
return c.ErrType
}
func (c *CustomError) Message() string {
return c.message
}
func (c *CustomError) Traces() []string {
var stack []string
if c.code != 0 && c.message != "" {
for i := 4; ; i++ {
pc, file, line, ok := runtime.Caller(i)
if !ok {
break
}
f := runtime.FuncForPC(pc)
if f.Name() != "runtime.main" && f.Name() != "runtime.goexit" {
str := fmt.Sprintf("file:%s, at dline:%d ,funcName:%s, error:%s", file, line, f.Name(), c.Error())
stack = append(stack, str)
}
}
}
return stack
}
func (c *CustomError) TraceString() string {
return strings.Join(c.Traces(), "\n")
}
func (c *CustomError) Set(key string, value interface{}) Base.ErrorInstance {
switch key {
case "code":
c.code = value.(int)
case "message":
if c.message != "" {
c.message = value.(string)
}
case "errorType":
if c.ErrType == "" {
c.ErrType = value.(string)
}
case "parent":
if c.Parent == nil {
switch value.(type) {
case Base.ErrorInstance:
c.Parent = value.(Base.ErrorInstance)
case error:
err := value.(error)
c.Parent = NewError(0, err.Error())
}
}
}
return c
}
func NewError(code int, msg string, parent ...error) Base.ErrorInstance {
return NewCustomError(msg, code, "error", parent...)
}
func (c *CustomError) New(msg string, code int, parent ...error) error {
return NewCustomError(msg, code, c.ErrType).Set("parent", parent)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。