43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// Api API接口定义,用于权限系统中注册可受控的HTTP接口
|
|
type Api struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Api) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Annotation{
|
|
Table: "api",
|
|
Options: "COMMENT='API接口表,注册系统中可受权限控制的HTTP接口,配合RBAC使用'",
|
|
},
|
|
entsql.WithComments(true),
|
|
}
|
|
}
|
|
|
|
func (Api) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int("id").Positive().Comment("主键ID"),
|
|
field.String("path").MaxLen(100).NotEmpty().Comment("API路径,如 /api/v1/users"),
|
|
field.String("method").MaxLen(20).NotEmpty().Comment("请求方法:GET/POST/PUT/DELETE"),
|
|
field.String("description").MaxLen(60).Optional().Comment("接口功能描述"),
|
|
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
|
|
}
|
|
}
|
|
|
|
func (Api) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("permissions", Permission.Type).Ref("apis").Comment("关联的权限项"),
|
|
}
|
|
}
|