Using uint64 for ErrorType

This commit is contained in:
Manu Mtz-Almeida 2015-05-23 01:59:36 +02:00
parent a373dc0deb
commit 2ebb6dcb95
2 changed files with 13 additions and 11 deletions

View File

@ -11,20 +11,22 @@ import (
"reflect"
)
const (
ErrorTypeBind = 1 << 30
ErrorTypeRender = 1 << 29
ErrorTypePrivate = 1 << 0
ErrorTypePublic = 1 << 1
type ErrorType uint64
ErrorTypeAny = 0xfffffff
const (
ErrorTypeBind ErrorType = 1 << 63 // used when c.Bind() fails
ErrorTypeRender ErrorType = 1 << 62 // used when c.Render() fails
ErrorTypePrivate ErrorType = 1 << 0
ErrorTypePublic ErrorType = 1 << 1
ErrorTypeAny ErrorType = 1<<64 - 1
ErrorTypeNu = 2
)
type (
Error struct {
Err error `json:"error"`
Type int `json:"-"`
Type ErrorType `json:"-"`
Meta interface{} `json:"meta"`
}
@ -33,7 +35,7 @@ type (
var _ error = &Error{}
func (msg *Error) SetType(flags int) *Error {
func (msg *Error) SetType(flags ErrorType) *Error {
msg.Type = flags
return msg
}
@ -72,7 +74,7 @@ func (msg *Error) Error() string {
return msg.Err.Error()
}
func (a errorMsgs) ByType(typ int) errorMsgs {
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
if len(a) == 0 {
return a
}

View File

@ -25,7 +25,7 @@ func ErrorLogger() HandlerFunc {
return ErrorLoggerT(ErrorTypeAny)
}
func ErrorLoggerT(typ int) HandlerFunc {
func ErrorLoggerT(typ ErrorType) HandlerFunc {
return func(c *Context) {
c.Next()