mirror of
https://github.com/ent/ent.git
synced 2026-04-28 05:30:56 +03:00
schema/field: relax signature of DefaultFunc for Bytes)(
This commit is contained in:
@@ -507,7 +507,7 @@ func (b *bytesBuilder) Default(v []byte) *bytesBuilder {
|
||||
// field.Bytes("cuid").
|
||||
// DefaultFunc(cuid.New)
|
||||
//
|
||||
func (b *bytesBuilder) DefaultFunc(fn func() []byte) *bytesBuilder {
|
||||
func (b *bytesBuilder) DefaultFunc(fn interface{}) *bytesBuilder {
|
||||
b.desc.Default = fn
|
||||
return b
|
||||
}
|
||||
@@ -597,6 +597,13 @@ func (b *bytesBuilder) SchemaType(types map[string]string) *bytesBuilder {
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *bytesBuilder) Descriptor() *Descriptor {
|
||||
// If the Default is present and a function, check that it's signtaure is appropriate.
|
||||
if b.desc.Default != nil {
|
||||
typ := reflect.TypeOf(b.desc.Default)
|
||||
if typ.Kind() == reflect.Func && (typ.NumIn() != 0 || typ.NumOut() != 1 || typ.Out(0).String() != b.desc.Info.String()) {
|
||||
b.desc.Err = fmt.Errorf("expect type (func() %s) for default value", b.desc.Info)
|
||||
}
|
||||
}
|
||||
return b.desc
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user