core/cerror/error.go

34 lines
448 B
Go
Raw Normal View History

2023-05-19 04:12:21 +00:00
package cerror
import (
"fmt"
)
type Error struct {
code *Code
msg string
kv map[string]interface{}
}
func (e *Error) Code() *Code {
return e.code
}
func (e *Error) Error() string {
return fmt.Sprintf("%s:%s", e.code, e.msg)
}
func (e *Error) KV(k string, v interface{}) {
e.kv[k] = v
}
func New(code *Code, message string) *Error {
e := &Error{
code: code,
msg: message,
kv: make(map[string]interface{}),
}
return e
}