feat: 添加认证、日志、响应等基础中间件与服务

This commit is contained in:
unclesam committed 2026-07-07 21:21:33 +08:00
1 parent 16a9f64109
commit 329a22f0b1
30 files changed
+1835 -12

No files matched your search

+35
View File
@@ -6,6 +6,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
@@ -27,8 +28,15 @@ const (
FieldIP = "ip"
// FieldAddr holds the string denoting the addr field in the database.
FieldAddr = "addr"
// EdgeRoles holds the string denoting the roles edge name in mutations.
EdgeRoles = "roles"
// Table holds the table name of the user in the database.
Table = "users"
// RolesTable is the table that holds the roles relation/edge. The primary key declared below.
RolesTable = "user_roles"
// RolesInverseTable is the table name for the Role entity.
// It exists in this package in order to avoid circular dependency with the "role" package.
RolesInverseTable = "roles"
)
// Columns holds all SQL columns for user fields.
@@ -43,6 +51,12 @@ var Columns = []string{
FieldAddr,
}
var (
// RolesPrimaryKey and RolesColumn2 are the table columns denoting the
// primary key for the roles relation (M2M).
RolesPrimaryKey = []string{"user_id", "role_id"}
)
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
@@ -112,3 +126,24 @@ func ByIP(opts ...sql.OrderTermOption) OrderOption {
func ByAddr(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAddr, opts...).ToFunc()
}
// ByRolesCount orders the results by roles count.
func ByRolesCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newRolesStep(), opts...)
}
}
// ByRoles orders the results by roles terms.
func ByRoles(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newRolesStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newRolesStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(RolesInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2M, false, RolesTable, RolesPrimaryKey...),
)
}