28 lines
415 B
Go
28 lines
415 B
Go
package ksrv
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type Error struct {
|
|
Code int `json:"code"`
|
|
Status string `json:"status"`
|
|
Message string `json:"msg"`
|
|
Tmpl string `json:"-"`
|
|
}
|
|
|
|
func (e Error) New(v ...interface{}) Error {
|
|
e.Message = fmt.Sprintf(e.Tmpl, v...)
|
|
return e
|
|
}
|
|
|
|
func (e Error) Error() string {
|
|
return e.Message
|
|
}
|
|
|
|
func (e Error) Json() []byte {
|
|
data, _ := json.Marshal(e)
|
|
return data
|
|
}
|