优惠券额度包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.go 576 B

12345678910111213141516171819202122232425262728293031323334
  1. package e
  2. import (
  3. "fmt"
  4. "path"
  5. "runtime"
  6. )
  7. type E struct {
  8. Code int // 错误码
  9. msg string // 报错代码
  10. st string // 堆栈信息
  11. }
  12. func NewErr(code int, msg string) error {
  13. return E{code, msg, stack(3)}
  14. }
  15. func (e E) Error() string {
  16. return e.msg
  17. }
  18. func stack(skip int) string {
  19. stk := make([]uintptr, 32)
  20. str := ""
  21. l := runtime.Callers(skip, stk[:])
  22. for i := 0; i < l; i++ {
  23. f := runtime.FuncForPC(stk[i])
  24. name := f.Name()
  25. file, line := f.FileLine(stk[i])
  26. str += fmt.Sprintf("\n%-30s[%s:%d]", name, path.Base(file), line)
  27. }
  28. return str
  29. }