go17/book/exception/exception.go

28 lines
477 B
Go

package exception
import (
"fmt"
)
func NewApiExceptin(code int, message string) *ApiExceptin {
return &ApiExceptin{
Code: code,
Message: message,
}
}
type ApiExceptin struct {
HttpCode int `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
}
func (e *ApiExceptin) WithHttpCode(httpCode int) *ApiExceptin {
e.HttpCode = httpCode
return e
}
func (e *ApiExceptin) Error() string {
return fmt.Sprintf("[%d] %s", e.Code, e.Message)
}