重构: GetAnonymous/GetSystemUser 改为指向 req/userx 的别名

实现搬到了 req/userx(详见 req 仓库对应提交),这里不再自己维护一份,
避免和 req 互相依赖导致 go.mod 只能靠指向本地兄弟目录的 replace 绕开
版本解析。

顺带清理 go.mod:condition/db/reflux/req 都不再需要 replace,锁定成各自
的真实版本号。
This commit is contained in:
2026-08-21 08:53:16 +08:00
parent 27b8c31a52
commit 6a5a6e5370
3 changed files with 47 additions and 96 deletions
+7 -70
View File
@@ -1,76 +1,13 @@
package base
import (
"github.com/samber/lo"
"git.fsdpf.net/go/req"
"git.fsdpf.net/go/req/userx"
)
type user struct {
id int64
uuid string
username string
nickname string
roles []string
runtime req.UserRuntime
}
// GetAnonymous 获取匿名用户。实现搬到了 req/userx(req 自己的子包,不反过来依赖 contracts),
// 这里保留只是兼容原有调用方,函数本身没法用 type = 起别名(type 只能别名类型,不能别名函数),
// 用 var 绑同一个函数值效果等价。
var GetAnonymous = userx.GetAnonymous
func (this user) ID() int64 {
return this.id
}
func (this user) Uuid() string {
return this.uuid
}
func (this user) Username() string {
return this.username
}
func (this user) Nickname() string {
return this.nickname
}
func (this user) GetUserInfo() map[string]any {
return nil
}
func (this user) Roles() (roles []string) {
return this.roles
}
func (this user) HasUserRoles(roles ...string) bool {
return lo.Contains(this.Roles(), "ffffffff-ffff-ffff-ffff-ffffffffffff") || len(lo.Intersect(this.Roles(), roles)) > 0
}
func (this user) IsAnonymous() bool {
return this.id == 0
}
func (this user) Runtime() req.UserRuntime {
return this.runtime
}
// GetAnonymous 获取匿名用户
func GetAnonymous(opts ...req.UserRuntimeOption) req.User {
return user{
id: 0,
uuid: "00000000-0000-0000-0000-000000000000",
username: "anonymous",
nickname: "匿名者",
roles: []string{"00000000-0000-0000-0000-000000000000"},
runtime: req.NewUserRuntime(opts...),
}
}
// GetSystemUser 系统用户
func GetSystemUser(opts ...req.UserRuntimeOption) req.User {
return user{
id: -1,
uuid: "ffffffff-ffff-ffff-ffff-ffffffffffff",
username: "system",
nickname: "系统",
roles: []string{"ffffffff-ffff-ffff-ffff-ffffffffffff"},
runtime: req.NewUserRuntime(opts...),
}
}
// GetSystemUser 系统用户,同上。
var GetSystemUser = userx.GetSystemUser