go17/book/exception/exception.go

28 lines
477 B
Go
Raw Normal View History

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