37 lines
484 B
Go
37 lines
484 B
Go
package ecode
|
|
|
|
import "github.com/kataras/iris/v12/mvc"
|
|
|
|
type Ecode struct {
|
|
Code int
|
|
Msg string
|
|
}
|
|
|
|
func (e *Ecode) Response() mvc.Result {
|
|
return mvc.Response{
|
|
Object: map[string]interface{}{
|
|
"code": e.Code,
|
|
"msg": e.Msg,
|
|
},
|
|
Code: 400,
|
|
}
|
|
}
|
|
|
|
func (e *Ecode) Error() bool {
|
|
return e.Code != 0
|
|
}
|
|
|
|
func Set(code int, msg string) *Ecode {
|
|
e := new(Ecode)
|
|
e.Code = code
|
|
e.Msg = msg
|
|
return e
|
|
}
|
|
|
|
func OK() *Ecode {
|
|
e := new(Ecode)
|
|
e.Code = 0
|
|
e.Msg = ""
|
|
return e
|
|
}
|