mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
entc/integration: add validator to macaddr field (#971)
This commit is contained in:
@@ -192,6 +192,8 @@ var (
|
||||
NdirValidator func(string) error
|
||||
// LinkValidator is a validator for the "link" field. It is called by the builders before save.
|
||||
LinkValidator func(string) error
|
||||
// MACValidator is a validator for the "mac" field. It is called by the builders before save.
|
||||
MACValidator func(string) error
|
||||
)
|
||||
|
||||
// State defines the type for the state enum field.
|
||||
|
||||
@@ -656,6 +656,11 @@ func (ftc *FieldTypeCreate) check() error {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf("ent: validator failed for field \"role\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ftc.mutation.MAC(); ok {
|
||||
if err := fieldtype.MACValidator(v.String()); err != nil {
|
||||
return &ValidationError{Name: "mac", err: fmt.Errorf("ent: validator failed for field \"mac\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1093,6 +1093,11 @@ func (ftu *FieldTypeUpdate) check() error {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf("ent: validator failed for field \"role\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ftu.mutation.MAC(); ok {
|
||||
if err := fieldtype.MACValidator(v.String()); err != nil {
|
||||
return &ValidationError{Name: "mac", err: fmt.Errorf("ent: validator failed for field \"mac\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2955,6 +2960,11 @@ func (ftuo *FieldTypeUpdateOne) check() error {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf("ent: validator failed for field \"role\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ftuo.mutation.MAC(); ok {
|
||||
if err := fieldtype.MACValidator(v.String()); err != nil {
|
||||
return &ValidationError{Name: "mac", err: fmt.Errorf("ent: validator failed for field \"mac\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ func init() {
|
||||
fieldtypeDescLink := fieldtypeFields[30].Descriptor()
|
||||
// fieldtype.LinkValidator is a validator for the "link" field. It is called by the builders before save.
|
||||
fieldtype.LinkValidator = fieldtypeDescLink.Validators[0].(func(string) error)
|
||||
// fieldtypeDescMAC is the schema descriptor for mac field.
|
||||
fieldtypeDescMAC := fieldtypeFields[45].Descriptor()
|
||||
// fieldtype.MACValidator is a validator for the "mac" field. It is called by the builders before save.
|
||||
fieldtype.MACValidator = fieldtypeDescMAC.Validators[0].(func(string) error)
|
||||
fileFields := schema.File{}.Fields()
|
||||
_ = fileFields
|
||||
// fileDescSize is the schema descriptor for size field.
|
||||
|
||||
@@ -135,6 +135,10 @@ func (FieldType) Fields() []ent.Field {
|
||||
GoType(&MAC{}).
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: "macaddr",
|
||||
}).
|
||||
Validate(func(s string) error {
|
||||
_, err := net.ParseMAC(s)
|
||||
return err
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,8 @@ var (
|
||||
NdirValidator func(string) error
|
||||
// LinkValidator is a validator for the "link" field. It is called by the builders before save.
|
||||
LinkValidator func(string) error
|
||||
// MACValidator is a validator for the "mac" field. It is called by the builders before save.
|
||||
MACValidator func(string) error
|
||||
)
|
||||
|
||||
// State defines the type for the state enum field.
|
||||
|
||||
@@ -657,6 +657,11 @@ func (ftc *FieldTypeCreate) check() error {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf("ent: validator failed for field \"role\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ftc.mutation.MAC(); ok {
|
||||
if err := fieldtype.MACValidator(v.String()); err != nil {
|
||||
return &ValidationError{Name: "mac", err: fmt.Errorf("ent: validator failed for field \"mac\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1095,6 +1095,11 @@ func (ftu *FieldTypeUpdate) check() error {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf("ent: validator failed for field \"role\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ftu.mutation.MAC(); ok {
|
||||
if err := fieldtype.MACValidator(v.String()); err != nil {
|
||||
return &ValidationError{Name: "mac", err: fmt.Errorf("ent: validator failed for field \"mac\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2537,6 +2542,11 @@ func (ftuo *FieldTypeUpdateOne) check() error {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf("ent: validator failed for field \"role\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ftuo.mutation.MAC(); ok {
|
||||
if err := fieldtype.MACValidator(v.String()); err != nil {
|
||||
return &ValidationError{Name: "mac", err: fmt.Errorf("ent: validator failed for field \"mac\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ func init() {
|
||||
fieldtypeDescLink := fieldtypeFields[30].Descriptor()
|
||||
// fieldtype.LinkValidator is a validator for the "link" field. It is called by the builders before save.
|
||||
fieldtype.LinkValidator = fieldtypeDescLink.Validators[0].(func(string) error)
|
||||
// fieldtypeDescMAC is the schema descriptor for mac field.
|
||||
fieldtypeDescMAC := fieldtypeFields[45].Descriptor()
|
||||
// fieldtype.MACValidator is a validator for the "mac" field. It is called by the builders before save.
|
||||
fieldtype.MACValidator = fieldtypeDescMAC.Validators[0].(func(string) error)
|
||||
fileFields := schema.File{}.Fields()
|
||||
_ = fileFields
|
||||
// fileDescSize is the schema descriptor for size field.
|
||||
|
||||
Reference in New Issue
Block a user