Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureCode(code string) (string, error)
- func FieldNameNormalize(name string) string
- func GenerateCode() (string, error)
- func GenerateCodeWithLen(length int) (string, error)
- func GenerateMenuCode(parentCode string) (string, error)
- func IsReservedCode(code string) bool
- func ValidateCode(code string) error
- type AuditMixin
- type AuthProviders
- type Credentials
- type Departments
- type GlobalSettings
- type Groups
- type Menus
- type OAuth2Clients
- type OAuth2Codes
- type Policies
- type PrincipalRoles
- type RoleMenus
- type RolePolicies
- type Roles
- type TimeMixin
- type TimeMixinWithoutDeleted
- type UserIdentities
- type UserMemberships
- type UserProfiles
- type Users
Constants ¶
const ( // CodeMinLen code 最小长度 CodeMinLen = 2 // CodeMaxLen code 最大长度 CodeMaxLen = 32 // CodeAutoLen 自动生成 code 的固定长度(通用,适用于 roles/departments/groups 等) CodeAutoLen = 12 // MenuCodeAutoLen 菜单专用自动生成 code 的随机部分长度 // 菜单 code 通常带父级前缀(如 admin.),6 位随机码足以保证唯一性 MenuCodeAutoLen = 6 )
Code 字段规范常量
Variables ¶
var ReservedMenuCodes = map[string]bool{ "root": true, "admin": true, "portal": true, "miniapp": true, "mobile": true, }
ReservedMenuCodes 是系统保留的菜单 code,不允许用户通过 CreateMenu 创建。 这些 code 对应内置的根菜单和端入口菜单,由 builtinMenuSeeds() 初始化。
var ( // URLRegex 验证 URL 格式的正则表达式,支持 http:// 和 https:// // 匹配格式: http://example.com, https://example.com/path, example.com/path URLRegex = regexp.MustCompile(`^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/?$`) )
Functions ¶
func EnsureCode ¶
EnsureCode 确保 code 有值:如果传入的 code 为空则自动生成,否则校验合法性。 不会检查保留码——保留码检查由调用方在合适的时机执行(如 CreateMenu)。 适用于 Create 接口中客户端可选提供 code 的场景。
func FieldNameNormalize ¶
FieldNameNormalize 移除字段名末尾的 "_encrypted", "_hash" 使其与 proto 等定义一致
func GenerateCode ¶
GenerateCode 自动生成一个 12 位的随机 code(通用,适用于 roles/departments/groups 等) 总组合数: 23 × 31^11 ≈ 1.79 × 10^17,碰撞概率极低
func GenerateCodeWithLen ¶
GenerateCodeWithLen 生成指定长度的随机 code 格式: [a-z] 开头 + (length-1) 位 [a-z0-9],使用 crypto/rand 确保加密安全 生成字符集移除了易混淆字符 i/l/o/0/1
func GenerateMenuCode ¶
GenerateMenuCode 生成菜单专用 code 当 parentCode 非空时,返回 "parentCode." + 6 位随机码(如 "admin.abc123") 当 parentCode 为空时,返回 6 位随机码(顶级菜单) 如果拼接后总长度超过 CodeMaxLen(32),则截断随机部分以适配
func ValidateCode ¶
ValidateCode 校验 code 是否符合规范 规则:
- 长度:2-32 字符
- 以小写字母 [a-z] 开头
- 中间允许 [a-z0-9.:-],不允许连续分隔符("--"、".."、"::"、"-."、".-"、".:"、":."、":-"、"-:")
- 以字母或数字 [a-z0-9] 结尾
- 不允许大写字母、下划线、空格等特殊字符
Types ¶
type AuditMixin ¶
AuditMixin 创建或更新人员属性
type AuthProviders ¶
AuthProviders 身份提供商实体,验证用户登录时使用的第三方服务 对应 proto: AuthProvider (admin.common.proto) 表名: lion_auth_providers
func (AuthProviders) Annotations ¶
func (AuthProviders) Annotations() []schema.Annotation
Annotations 自定义表名
type Credentials ¶
Credentials holds the schema definition for the Credentials entity.
func (Credentials) Annotations ¶
func (Credentials) Annotations() []schema.Annotation
Annotations 自定义表名
type Departments ¶
Departments 组织架构部门管理
func (Departments) Annotations ¶
func (Departments) Annotations() []schema.Annotation
Annotations 自定义表名
type GlobalSettings ¶
GlobalSettings holds the schema definition for the GlobalSettings entity.
func (GlobalSettings) Annotations ¶
func (GlobalSettings) Annotations() []schema.Annotation
Annotations 自定义表名
type OAuth2Clients ¶
OAuth2Clients OAuth2 客户端注册表 表名: lion_oauth2_clients 存储 OAuth2 客户端注册信息,支持 Authorization Code + PKCE + Refresh Token 流程
func (OAuth2Clients) Annotations ¶
func (OAuth2Clients) Annotations() []schema.Annotation
Annotations 自定义表名
type OAuth2Codes ¶
OAuth2Codes OAuth2 授权码存储表 表名: lion_oauth2_codes 存储 Authorization Code + PKCE 流程中的授权码信息 安全设计:不存储授权码明文,仅存储 SHA-256 hash,DB 泄露后授权码不可直接使用
func (OAuth2Codes) Annotations ¶
func (OAuth2Codes) Annotations() []schema.Annotation
Annotations 自定义表名
type PrincipalRoles ¶
PrincipalRoles 表示用户、群组、部门到角色的统一绑定关系。
func (PrincipalRoles) Annotations ¶
func (PrincipalRoles) Annotations() []schema.Annotation
Annotations 自定义表名。
type RolePolicies ¶
RolePolicies 角色与策略的关联关系。
func (RolePolicies) Annotations ¶
func (RolePolicies) Annotations() []schema.Annotation
Annotations 自定义表名
type TimeMixinWithoutDeleted ¶
TimeMixinWithoutDeleted xx
func (TimeMixinWithoutDeleted) Fields ¶
func (TimeMixinWithoutDeleted) Fields() []ent.Field
Fields xx
type UserIdentities ¶
UserIdentities 存储通过 OIDC 等社交登录的用户信息
func (UserIdentities) Annotations ¶
func (UserIdentities) Annotations() []schema.Annotation
Annotations 自定义表名
type UserMemberships ¶
UserMemberships 表示用户到群组/部门的统一静态归属关系。
func (UserMemberships) Annotations ¶
func (UserMemberships) Annotations() []schema.Annotation
Annotations 自定义表名。
type UserProfiles ¶
UserProfiles 用于存储用户的扩展属性信息
func (UserProfiles) Annotations ¶
func (UserProfiles) Annotations() []schema.Annotation
Annotations 自定义表名