Files
v2ray_simple/utils/error.go
hahahrfool 250f6e8c5b 新增http代理Server端.修订代码,注释.CommonConf加了Extra字段
CommonConf加了这一行:Extra map[string]interface{} `toml:"extra"`

这样就可以兼容一切未来未知的格式了, 同时 proxy包的 ClientCreator和 ServerCreator接口
也相应改动了,不再需要传入 map.
2022-03-19 16:43:55 +08:00

58 lines
990 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package utils
import "fmt"
func NewErr(desc string, e error) *ErrInErr {
return &ErrInErr{
ErrDesc: desc,
ErrDetail: e,
}
}
func NewDataErr(desc string, e error, data interface{}) *ErrInErr {
return &ErrInErr{
ErrDesc: desc,
ErrDetail: e,
Data: data,
}
}
// ErrInErr 很适合一个err包含另一个err并且提供附带数据的情况
type ErrInErr struct {
ErrDesc string
ErrDetail error
Data interface{}
cachedStr string
}
func (e *ErrInErr) Error() string {
return e.String()
}
func (e *ErrInErr) String() string {
if e.cachedStr == "" {
e.cachedStr = e.string()
}
return e.cachedStr
}
func (e *ErrInErr) string() string {
if e.Data != nil {
if e.ErrDetail != nil {
return fmt.Sprintf("%s : %s, Data: %v", e.ErrDesc, e.ErrDetail.Error(), e.Data)
}
return fmt.Sprintf("%s , Data: %v", e.ErrDesc, e.Data)
}
if e.ErrDetail != nil {
return fmt.Sprintf("%s : %s", e.ErrDesc, e.ErrDetail.Error())
}
return e.ErrDesc
}