refactor: clean code

This commit is contained in:
Fu Diwei
2025-01-16 20:27:30 +08:00
parent dea4106569
commit 8ecb71fb55
39 changed files with 440 additions and 258 deletions

30
internal/domain/error.go Normal file
View File

@@ -0,0 +1,30 @@
package domain
var (
ErrInvalidParams = NewError(400, "invalid params")
ErrRecordNotFound = NewError(404, "record not found")
)
type Error struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
func NewError(code int, msg string) *Error {
if code == 0 {
code = -1
}
return &Error{code, msg}
}
func (e *Error) Error() string {
return e.Msg
}
func IsRecordNotFoundError(err error) bool {
if e, ok := err.(*Error); ok {
return e.Code == ErrRecordNotFound.Code
}
return false
}