refactor(server): 会话/访客/设置业务逻辑下沉 internal/service 层,handler 瘦身
- handler 只保留请求绑定、权限检查与响应映射;业务校验顺序、状态码与文案逐字保留 - 新增 service.Error 语义错误,由 handler 统一映射 HTTP 响应 - session 875→361 行、widget 745→321 行、settings 540→73 行 - 自动分配/租户设置(工作时间、欢迎语)/消息校验/黑名单检查/联系方式提取随迁 service 包 - 相关单元测试随迁 service 包,go test ./... 全部通过
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package service
|
||||
|
||||
// Error 带语义状态码的业务错误,由 handler 层映射为 HTTP 响应。
|
||||
type Error struct {
|
||||
Status int
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e *Error) Error() string { return e.Message }
|
||||
|
||||
// E 构造业务错误。
|
||||
func E(status int, message string) *Error {
|
||||
return &Error{Status: status, Message: message}
|
||||
}
|
||||
|
||||
// BadRequest / Forbidden / NotFound / Conflict / Internal 便捷构造。
|
||||
func BadRequest(message string) *Error { return &Error{Status: 400, Message: message} }
|
||||
func Forbidden(message string) *Error { return &Error{Status: 403, Message: message} }
|
||||
func NotFound(message string) *Error { return &Error{Status: 404, Message: message} }
|
||||
func Conflict(message string) *Error { return &Error{Status: 409, Message: message} }
|
||||
func Internal(message string) *Error { return &Error{Status: 500, Message: message} }
|
||||
Reference in New Issue
Block a user