mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
improve
- AuthMiddleware 注入当前用户的信息
- 增加Context服务支持快捷获取当前登录者信息
- 重构Login/GetMe接口逻辑避免重复的数据库查询
- 规范化error信息声明(向下兼容,旧代码可逐渐迁移规范化)
- 修正部分不符合规范的代码
44 lines
692 B
Go
44 lines
692 B
Go
package errors
|
|
|
|
import "fmt"
|
|
|
|
type Scope int
|
|
|
|
const (
|
|
ScopeSystem Scope = 1
|
|
ScopeBusiness Scope = 2
|
|
)
|
|
|
|
type OPError struct {
|
|
Message string
|
|
Code int
|
|
Scope Scope
|
|
}
|
|
|
|
func (O OPError) Error() string {
|
|
var scope string
|
|
switch O.Scope {
|
|
case ScopeSystem:
|
|
scope = "system"
|
|
break
|
|
case ScopeBusiness:
|
|
scope = "business"
|
|
}
|
|
return fmt.Sprintf("%s : %d -> %s.", scope, O.Code, O.Message)
|
|
}
|
|
|
|
func NewSystemOPError(code int, message string) *OPError {
|
|
return &OPError{
|
|
Message: message,
|
|
Code: code,
|
|
Scope: ScopeSystem,
|
|
}
|
|
}
|
|
func NewBusinessError(code int, message string) *OPError {
|
|
return &OPError{
|
|
Message: message,
|
|
Code: code,
|
|
Scope: ScopeBusiness,
|
|
}
|
|
}
|