34 lines
448 B
Go
34 lines
448 B
Go
|
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
|
||
|
}
|