48 lines
957 B
Go
48 lines
957 B
Go
package schema
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// User holds the schema definition for the User entity.
|
|
type User struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (User) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
BaseMixin{},
|
|
}
|
|
}
|
|
|
|
// Fields of the User.
|
|
func (User) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("username").
|
|
Unique().
|
|
NotEmpty(),
|
|
field.String("password").
|
|
Sensitive(),
|
|
field.String("email").
|
|
Optional().
|
|
Match(regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)), // 邮箱格式正则校验
|
|
field.String("ip").
|
|
Optional().
|
|
Match(regexp.MustCompile(`^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$`)),
|
|
field.String("addr").
|
|
Optional().
|
|
MaxLen(500),
|
|
}
|
|
}
|
|
|
|
// Edges of the User.
|
|
func (User) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.To("roles", Role.Type),
|
|
}
|
|
}
|