feat: 添加认证、日志、响应等基础中间件与服务
This commit is contained in:
1 parent
16a9f64109
commit
329a22f0b1
30 files changed
+1835
-12
No files matched your search
@@ -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...),
|
||||
)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
@@ -524,6 +525,29 @@ func AddrContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldAddr, v))
|
||||
}
|
||||
|
||||
// HasRoles applies the HasEdge predicate on the "roles" edge.
|
||||
func HasRoles() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, RolesTable, RolesPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasRolesWith applies the HasEdge predicate on the "roles" edge with a given conditions (other predicates).
|
||||
func HasRolesWith(preds ...predicate.Role) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newRolesStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(sql.AndPredicates(predicates...))
|
||||
|
||||
Reference in new issue
Block a user