schema

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var ReservedMenuCodes = map[string]bool{
	"root":    true,
	"admin":   true,
	"portal":  true,
	"miniapp": true,
	"mobile":  true,
}

ReservedMenuCodes 是系统保留的菜单 code,不允许用户通过 CreateMenu 创建。 这些 code 对应内置的根菜单和端入口菜单,由 builtinMenuSeeds() 初始化。

View Source
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

func EnsureCode(code string) (string, error)

EnsureCode 确保 code 有值:如果传入的 code 为空则自动生成,否则校验合法性。 不会检查保留码——保留码检查由调用方在合适的时机执行(如 CreateMenu)。 适用于 Create 接口中客户端可选提供 code 的场景。

func FieldNameNormalize

func FieldNameNormalize(name string) string

FieldNameNormalize 移除字段名末尾的 "_encrypted", "_hash" 使其与 proto 等定义一致

func GenerateCode

func GenerateCode() (string, error)

GenerateCode 自动生成一个 12 位的随机 code(通用,适用于 roles/departments/groups 等) 总组合数: 23 × 31^11 ≈ 1.79 × 10^17,碰撞概率极低

func GenerateCodeWithLen

func GenerateCodeWithLen(length int) (string, error)

GenerateCodeWithLen 生成指定长度的随机 code 格式: [a-z] 开头 + (length-1) 位 [a-z0-9],使用 crypto/rand 确保加密安全 生成字符集移除了易混淆字符 i/l/o/0/1

func GenerateMenuCode

func GenerateMenuCode(parentCode string) (string, error)

GenerateMenuCode 生成菜单专用 code 当 parentCode 非空时,返回 "parentCode." + 6 位随机码(如 "admin.abc123") 当 parentCode 为空时,返回 6 位随机码(顶级菜单) 如果拼接后总长度超过 CodeMaxLen(32),则截断随机部分以适配

func IsReservedCode

func IsReservedCode(code string) bool

IsReservedCode 检查给定 code 是否为系统保留码。

func ValidateCode

func ValidateCode(code string) error

ValidateCode 校验 code 是否符合规范 规则:

  • 长度:2-32 字符
  • 以小写字母 [a-z] 开头
  • 中间允许 [a-z0-9.:-],不允许连续分隔符("--"、".."、"::"、"-."、".-"、".:"、":."、":-"、"-:")
  • 以字母或数字 [a-z0-9] 结尾
  • 不允许大写字母、下划线、空格等特殊字符

Types

type AuditMixin

type AuditMixin struct {
	mixin.Schema
}

AuditMixin 创建或更新人员属性

func (AuditMixin) Fields

func (AuditMixin) Fields() []ent.Field

Fields xx

type AuthProviders

type AuthProviders struct {
	ent.Schema
}

AuthProviders 身份提供商实体,验证用户登录时使用的第三方服务 对应 proto: AuthProvider (admin.common.proto) 表名: lion_auth_providers

func (AuthProviders) Annotations

func (AuthProviders) Annotations() []schema.Annotation

Annotations 自定义表名

func (AuthProviders) Edges

func (AuthProviders) Edges() []ent.Edge

Edges of the table.

func (AuthProviders) Fields

func (AuthProviders) Fields() []ent.Field

Fields of the table.

func (AuthProviders) Indexes

func (AuthProviders) Indexes() []ent.Index

Indexes 定义索引

func (AuthProviders) Mixin

func (AuthProviders) Mixin() []ent.Mixin

Mixin of the table.

type Credentials

type Credentials struct {
	ent.Schema
}

Credentials holds the schema definition for the Credentials entity.

func (Credentials) Annotations

func (Credentials) Annotations() []schema.Annotation

Annotations 自定义表名

func (Credentials) Edges

func (Credentials) Edges() []ent.Edge

Edges of the table.

func (Credentials) Fields

func (Credentials) Fields() []ent.Field

Fields of the table.

func (Credentials) Mixin

func (Credentials) Mixin() []ent.Mixin

Mixin of the table.

type Departments

type Departments struct {
	ent.Schema
}

Departments 组织架构部门管理

func (Departments) Annotations

func (Departments) Annotations() []schema.Annotation

Annotations 自定义表名

func (Departments) Edges

func (Departments) Edges() []ent.Edge

Edges of the table.

func (Departments) Fields

func (Departments) Fields() []ent.Field

Fields of the table.

func (Departments) Mixin

func (Departments) Mixin() []ent.Mixin

Mixin of the table.

type GlobalSettings

type GlobalSettings struct {
	ent.Schema
}

GlobalSettings holds the schema definition for the GlobalSettings entity.

func (GlobalSettings) Annotations

func (GlobalSettings) Annotations() []schema.Annotation

Annotations 自定义表名

func (GlobalSettings) Fields

func (GlobalSettings) Fields() []ent.Field

Fields of the table.

func (GlobalSettings) Indexes

func (GlobalSettings) Indexes() []ent.Index

Indexes of the table.

func (GlobalSettings) Mixin

func (GlobalSettings) Mixin() []ent.Mixin

Mixin of the table.

type Groups

type Groups struct {
	ent.Schema
}

Groups 存储用户组信息,实现 RBAC 权限管理

func (Groups) Annotations

func (Groups) Annotations() []schema.Annotation

Annotations 自定义表名

func (Groups) Edges

func (Groups) Edges() []ent.Edge

Edges of the table.

func (Groups) Fields

func (Groups) Fields() []ent.Field

Fields of the table.

func (Groups) Indexes

func (Groups) Indexes() []ent.Index

Indexes 定义索引

func (Groups) Mixin

func (Groups) Mixin() []ent.Mixin

Mixin of the table.

type Menus struct {
	ent.Schema
}

Menus holds the schema definition for the Menus entity.

func (Menus) Annotations() []schema.Annotation

Annotations 自定义表名

func (Menus) Edges() []ent.Edge

Edges of the table.

func (Menus) Fields() []ent.Field

Fields of the table.

func (Menus) Indexes() []ent.Index

Indexes of the table.

func (Menus) Mixin() []ent.Mixin

Mixin of the table.

type OAuth2Clients

type OAuth2Clients struct {
	ent.Schema
}

OAuth2Clients OAuth2 客户端注册表 表名: lion_oauth2_clients 存储 OAuth2 客户端注册信息,支持 Authorization Code + PKCE + Refresh Token 流程

func (OAuth2Clients) Annotations

func (OAuth2Clients) Annotations() []schema.Annotation

Annotations 自定义表名

func (OAuth2Clients) Edges

func (OAuth2Clients) Edges() []ent.Edge

Edges of the table.

func (OAuth2Clients) Fields

func (OAuth2Clients) Fields() []ent.Field

Fields of the table.

func (OAuth2Clients) Indexes

func (OAuth2Clients) Indexes() []ent.Index

Indexes 定义索引

func (OAuth2Clients) Mixin

func (OAuth2Clients) Mixin() []ent.Mixin

Mixin of the table.

type OAuth2Codes

type OAuth2Codes struct {
	ent.Schema
}

OAuth2Codes OAuth2 授权码存储表 表名: lion_oauth2_codes 存储 Authorization Code + PKCE 流程中的授权码信息 安全设计:不存储授权码明文,仅存储 SHA-256 hash,DB 泄露后授权码不可直接使用

func (OAuth2Codes) Annotations

func (OAuth2Codes) Annotations() []schema.Annotation

Annotations 自定义表名

func (OAuth2Codes) Edges

func (OAuth2Codes) Edges() []ent.Edge

Edges of the table.

func (OAuth2Codes) Fields

func (OAuth2Codes) Fields() []ent.Field

Fields of the table.

func (OAuth2Codes) Indexes

func (OAuth2Codes) Indexes() []ent.Index

Indexes 定义索引

func (OAuth2Codes) Mixin

func (OAuth2Codes) Mixin() []ent.Mixin

Mixin of the table.

type Policies

type Policies struct {
	ent.Schema
}

Policies holds the schema definition for the Policies entity.

func (Policies) Annotations

func (Policies) Annotations() []schema.Annotation

Annotations 自定义表名

func (Policies) Edges

func (Policies) Edges() []ent.Edge

Edges of the table.

func (Policies) Fields

func (Policies) Fields() []ent.Field

Fields of the table.

func (Policies) Indexes

func (Policies) Indexes() []ent.Index

Indexes 定义索引

func (Policies) Mixin

func (Policies) Mixin() []ent.Mixin

Mixin of the table.

type PrincipalRoles

type PrincipalRoles struct {
	ent.Schema
}

PrincipalRoles 表示用户、群组、部门到角色的统一绑定关系。

func (PrincipalRoles) Annotations

func (PrincipalRoles) Annotations() []schema.Annotation

Annotations 自定义表名。

func (PrincipalRoles) Edges

func (PrincipalRoles) Edges() []ent.Edge

Edges of the table.

func (PrincipalRoles) Fields

func (PrincipalRoles) Fields() []ent.Field

Fields of the table.

func (PrincipalRoles) Indexes

func (PrincipalRoles) Indexes() []ent.Index

Indexes of the table.

func (PrincipalRoles) Mixin

func (PrincipalRoles) Mixin() []ent.Mixin

Mixin of the table.

type RoleMenus

type RoleMenus struct {
	ent.Schema
}

RoleMenus 角色与菜单的关联关系

func (RoleMenus) Annotations

func (RoleMenus) Annotations() []schema.Annotation

Annotations 自定义表名

func (RoleMenus) Edges

func (RoleMenus) Edges() []ent.Edge

Edges of the table.

func (RoleMenus) Fields

func (RoleMenus) Fields() []ent.Field

Fields of the table.

func (RoleMenus) Indexes

func (RoleMenus) Indexes() []ent.Index

Indexes of the table.

func (RoleMenus) Mixin

func (RoleMenus) Mixin() []ent.Mixin

Mixin of the table.

type RolePolicies

type RolePolicies struct {
	ent.Schema
}

RolePolicies 角色与策略的关联关系。

func (RolePolicies) Annotations

func (RolePolicies) Annotations() []schema.Annotation

Annotations 自定义表名

func (RolePolicies) Edges

func (RolePolicies) Edges() []ent.Edge

Edges of the table.

func (RolePolicies) Fields

func (RolePolicies) Fields() []ent.Field

Fields of the table.

func (RolePolicies) Indexes

func (RolePolicies) Indexes() []ent.Index

Indexes of the table.

func (RolePolicies) Mixin

func (RolePolicies) Mixin() []ent.Mixin

Mixin of the table.

type Roles

type Roles struct {
	ent.Schema
}

Roles holds the schema definition for the Demo entity.

func (Roles) Annotations

func (Roles) Annotations() []schema.Annotation

Annotations 自定义表名

func (Roles) Edges

func (Roles) Edges() []ent.Edge

Edges of the table.

func (Roles) Fields

func (Roles) Fields() []ent.Field

Fields of the table.

func (Roles) Indexes

func (Roles) Indexes() []ent.Index

Indexes 定义索引

func (Roles) Mixin

func (Roles) Mixin() []ent.Mixin

Mixin of the table.

type TimeMixin

type TimeMixin struct {
	mixin.Schema
}

TimeMixin xx

func (TimeMixin) Fields

func (TimeMixin) Fields() []ent.Field

Fields xx

type TimeMixinWithoutDeleted

type TimeMixinWithoutDeleted struct {
	mixin.Schema
}

TimeMixinWithoutDeleted xx

func (TimeMixinWithoutDeleted) Fields

func (TimeMixinWithoutDeleted) Fields() []ent.Field

Fields xx

type UserIdentities

type UserIdentities struct {
	ent.Schema
}

UserIdentities 存储通过 OIDC 等社交登录的用户信息

func (UserIdentities) Annotations

func (UserIdentities) Annotations() []schema.Annotation

Annotations 自定义表名

func (UserIdentities) Edges

func (UserIdentities) Edges() []ent.Edge

Edges of the table.

func (UserIdentities) Fields

func (UserIdentities) Fields() []ent.Field

Fields of the table.

func (UserIdentities) Indexes

func (UserIdentities) Indexes() []ent.Index

Indexes of the table.

func (UserIdentities) Mixin

func (UserIdentities) Mixin() []ent.Mixin

Mixin of the table.

type UserMemberships

type UserMemberships struct {
	ent.Schema
}

UserMemberships 表示用户到群组/部门的统一静态归属关系。

func (UserMemberships) Annotations

func (UserMemberships) Annotations() []schema.Annotation

Annotations 自定义表名。

func (UserMemberships) Edges

func (UserMemberships) Edges() []ent.Edge

Edges of the table.

func (UserMemberships) Fields

func (UserMemberships) Fields() []ent.Field

Fields of the table.

func (UserMemberships) Indexes

func (UserMemberships) Indexes() []ent.Index

Indexes of the table.

func (UserMemberships) Mixin

func (UserMemberships) Mixin() []ent.Mixin

Mixin of the table.

type UserProfiles

type UserProfiles struct {
	ent.Schema
}

UserProfiles 用于存储用户的扩展属性信息

func (UserProfiles) Annotations

func (UserProfiles) Annotations() []schema.Annotation

Annotations 自定义表名

func (UserProfiles) Edges

func (UserProfiles) Edges() []ent.Edge

Edges of the table.

func (UserProfiles) Fields

func (UserProfiles) Fields() []ent.Field

Fields of the table.

func (UserProfiles) Indexes

func (UserProfiles) Indexes() []ent.Index

Indexes of the table.

func (UserProfiles) Mixin

func (UserProfiles) Mixin() []ent.Mixin

Mixin of the table.

type Users

type Users struct {
	ent.Schema
}

Users 用户实体表 | 存储用户基本信息和认证相关字段

func (Users) Annotations

func (Users) Annotations() []schema.Annotation

Annotations 自定义表名

func (Users) Edges

func (Users) Edges() []ent.Edge

Edges of the table.

func (Users) Fields

func (Users) Fields() []ent.Field

Fields of the table.

func (Users) Indexes

func (Users) Indexes() []ent.Index

Indexes 定义索引 索引策略说明: 1. 单字段索引:保留高频单独使用的字段(user_type, user_status) 2. 组合索引:根据实际查询模式优化,遵循最左前缀原则 3. 唯一索引:哈希字段使用条件唯一索引(仅非空值唯一) 4. 查询模式:通常过滤 deleted_at IS NULL + user_status/user_type + 按 created_at 排序

func (Users) Mixin

func (Users) Mixin() []ent.Mixin

Mixin of the table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL