From 952a34c9c2e8da4b4da84a3a75957abcda4ea8c3 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sat, 2 Jan 2021 22:39:51 -0800 Subject: [PATCH 1/5] schema/field: relax signature of DefaultFunc for String() --- schema/field/field.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/schema/field/field.go b/schema/field/field.go index ba0ee20f6..9180ce343 100644 --- a/schema/field/field.go +++ b/schema/field/field.go @@ -213,7 +213,7 @@ func (b *stringBuilder) Default(s string) *stringBuilder { // field.String("cuid"). // DefaultFunc(cuid.New) // -func (b *stringBuilder) DefaultFunc(fn func() string) *stringBuilder { +func (b *stringBuilder) DefaultFunc(fn interface{}) *stringBuilder { b.desc.Default = fn return b } @@ -295,6 +295,13 @@ func (b *stringBuilder) Annotations(annotations ...schema.Annotation) *stringBui // Descriptor implements the ent.Field interface by returning its descriptor. func (b *stringBuilder) 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 } From 53dfe9593679172d76d7901507c55ef907185f9d Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sun, 3 Jan 2021 13:21:00 -0800 Subject: [PATCH 2/5] schema/field: relax signature of DefaultFunc for Bytes)( --- schema/field/field.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/schema/field/field.go b/schema/field/field.go index 9180ce343..af1a72764 100644 --- a/schema/field/field.go +++ b/schema/field/field.go @@ -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 } From 784fc18380a1ee654998d60ea558ac7b9b179cea Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Sun, 3 Jan 2021 13:43:15 -0800 Subject: [PATCH 3/5] schema/field: reflect the aliasing of byte in check --- schema/field/field.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/schema/field/field.go b/schema/field/field.go index af1a72764..da29d7e9f 100644 --- a/schema/field/field.go +++ b/schema/field/field.go @@ -600,7 +600,8 @@ 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()) { + // We check against "[]uint8" here because the reflect package treats byte as an alias to uint8. + if typ.Kind() == reflect.Func && (typ.NumIn() != 0 || typ.NumOut() != 1 || typ.Out(0).String() != "[]uint8") { b.desc.Err = fmt.Errorf("expect type (func() %s) for default value", b.desc.Info) } } From d514d12dabc69056fe9b470415e88fd03ae4fe20 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Mon, 4 Jan 2021 11:23:52 +0200 Subject: [PATCH 4/5] schema/field: check assignment and add tests for defaultfunc --- schema/field/field.go | 32 ++++++++++++++-------- schema/field/field_test.go | 54 +++++++++++++++++++++++++++++++++++--- schema/field/type.go | 2 ++ 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/schema/field/field.go b/schema/field/field.go index da29d7e9f..fc4ae0a53 100644 --- a/schema/field/field.go +++ b/schema/field/field.go @@ -295,12 +295,8 @@ func (b *stringBuilder) Annotations(annotations ...schema.Annotation) *stringBui // Descriptor implements the ent.Field interface by returning its descriptor. func (b *stringBuilder) 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) - } + b.desc.checkDefaultFunc(stringType) } return b.desc } @@ -597,13 +593,8 @@ 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) - // We check against "[]uint8" here because the reflect package treats byte as an alias to uint8. - if typ.Kind() == reflect.Func && (typ.NumIn() != 0 || typ.NumOut() != 1 || typ.Out(0).String() != "[]uint8") { - b.desc.Err = fmt.Errorf("expect type (func() %s) for default value", b.desc.Info) - } + b.desc.checkDefaultFunc(bytesType) } return b.desc } @@ -926,6 +917,7 @@ func (d *Descriptor) goType(typ interface{}, expectType reflect.Type) { Ident: tv.String(), PkgPath: tv.PkgPath(), RType: &RType{ + rtype: tv, Name: tv.Name(), Kind: tv.Kind(), PkgPath: tv.PkgPath(), @@ -963,6 +955,24 @@ func (d *Descriptor) goType(typ interface{}, expectType reflect.Type) { d.Info = info } +func (d *Descriptor) checkDefaultFunc(expectType reflect.Type) { + typ := reflect.TypeOf(d.Default) + if typ.Kind() != reflect.Func || d.Err != nil { + return + } + err := fmt.Errorf("expect type (func() %s) for default value", d.Info) + if typ.NumIn() != 0 || typ.NumOut() != 1 { + d.Err = err + } + rtype := expectType + if d.Info.RType != nil { + rtype = d.Info.RType.rtype + } + if !typ.Out(0).AssignableTo(rtype) { + d.Err = err + } +} + var ( boolType = reflect.TypeOf(false) bytesType = reflect.TypeOf([]byte(nil)) diff --git a/schema/field/field_test.go b/schema/field/field_test.go index f816f4cb1..8ac149328 100644 --- a/schema/field/field_test.go +++ b/schema/field/field_test.go @@ -185,8 +185,8 @@ func TestBytes(t *testing.T) { fd = field.Bytes("uuid"). GoType(&uuid.UUID{}). - DefaultFunc(func() []byte { - return []byte("{}") + DefaultFunc(func() uuid.UUID { + return uuid.New() }). Descriptor() assert.NoError(t, fd.Err) @@ -195,7 +195,7 @@ func TestBytes(t *testing.T) { assert.Equal(t, "uuid.UUID", fd.Info.String()) assert.True(t, fd.Info.Nillable) assert.True(t, fd.Info.ValueScanner()) - assert.Equal(t, []byte("{}"), fd.Default.(func() []byte)()) + assert.NotEmpty(t, fd.Default.(func() uuid.UUID)()) fd = field.Bytes("blob").GoType(1).Descriptor() assert.Error(t, fd.Err) @@ -205,6 +205,54 @@ func TestBytes(t *testing.T) { assert.Error(t, fd.Err) } +func TestBytes_DefaultFunc(t *testing.T) { + f1 := func() net.IP { return net.IP("0.0.0.0") } + fd := field.Bytes("ip").GoType(net.IP("127.0.0.1")).DefaultFunc(f1).Descriptor() + assert.NoError(t, fd.Err) + + var _ []byte = f1() + fd = field.Bytes("ip").DefaultFunc(f1).Descriptor() + assert.NoError(t, fd.Err) + + f2 := func() []byte { return []byte("0.0.0.0") } + var _ net.IP = f2() + fd = field.Bytes("ip").GoType(net.IP("127.0.0.1")).DefaultFunc(f2).Descriptor() + assert.NoError(t, fd.Err) + + f3 := func() []uint8 { return []uint8("0.0.0.0") } + var _ net.IP = f3() + fd = field.Bytes("ip").GoType(net.IP("127.0.0.1")).DefaultFunc(f3).Descriptor() + assert.NoError(t, fd.Err) + fd = field.Bytes("ip").DefaultFunc(f3).Descriptor() + assert.NoError(t, fd.Err) + + f4 := func() net.IPMask { return net.IPMask("ffff:ff80::") } + fd = field.Bytes("ip").GoType(net.IP("127.0.0.1")).DefaultFunc(f4).Descriptor() + assert.Error(t, fd.Err, "`var _ net.IP = f4()` should fail") +} + +func TestString_DefaultFunc(t *testing.T) { + f1 := func() http.Dir { return "/tmp" } + fd := field.String("dir").GoType(http.Dir("/tmp")).DefaultFunc(f1).Descriptor() + assert.NoError(t, fd.Err) + + fd = field.String("dir").DefaultFunc(f1).Descriptor() + assert.Error(t, fd.Err, "`var _ string = f1()` should fail") + + f2 := func() string { return "/tmp" } + fd = field.String("dir").GoType(http.Dir("/tmp")).DefaultFunc(f2).Descriptor() + assert.Error(t, fd.Err, "`var _ http.Dir = f2()` should fail") + + f3 := func() sql.NullString { return sql.NullString{} } + fd = field.String("str").GoType(&sql.NullString{}).DefaultFunc(f3).Descriptor() + assert.NoError(t, fd.Err) + + type S string + f4 := func() S { return "" } + fd = field.String("str").GoType(http.Dir("/tmp")).DefaultFunc(f4).Descriptor() + assert.Error(t, fd.Err, "`var _ http.Dir = f4()` should fail") +} + func TestString(t *testing.T) { fd := field.String("name"). DefaultFunc(func() string { diff --git a/schema/field/type.go b/schema/field/type.go index 52408de91..734b852b6 100644 --- a/schema/field/type.go +++ b/schema/field/type.go @@ -179,6 +179,8 @@ type RType struct { Kind reflect.Kind PkgPath string Methods map[string]struct{ In, Out []*RType } + // Used only for in-package checks. + rtype reflect.Type } // TypeEqual tests if the RType is equal to given reflect.Type. From 2ab0c682db2effe2d730be5fa4c895e8f4bfb1d5 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Mon, 4 Jan 2021 11:45:36 +0200 Subject: [PATCH 5/5] entc/integ: add tests for default-func --- .golangci.yml | 2 +- entc/integration/ent/fieldtype/fieldtype.go | 8 ++++++++ entc/integration/ent/fieldtype_create.go | 12 ++++++++++++ entc/integration/ent/runtime.go | 14 ++++++++++++++ entc/integration/ent/schema/fieldtype.go | 15 ++++++++++++--- .../gremlin/ent/fieldtype/fieldtype.go | 8 ++++++++ entc/integration/gremlin/ent/fieldtype_create.go | 12 ++++++++++++ entc/integration/gremlin/ent/runtime.go | 14 ++++++++++++++ entc/integration/type_test.go | 8 ++++---- schema/field/field_test.go | 4 +--- 10 files changed, 86 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e2899b2a2..c033ab45a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,7 +7,7 @@ linters-settings: dupl: threshold: 100 funlen: - lines: 120 + lines: 130 statements: 80 goheader: template: |- diff --git a/entc/integration/ent/fieldtype/fieldtype.go b/entc/integration/ent/fieldtype/fieldtype.go index e8db88a6c..02f897c5b 100644 --- a/entc/integration/ent/fieldtype/fieldtype.go +++ b/entc/integration/ent/fieldtype/fieldtype.go @@ -8,7 +8,9 @@ package fieldtype import ( "fmt" + "net" + "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/entc/integration/ent/role" ) @@ -193,8 +195,14 @@ var ( ValidateOptionalInt32Validator func(int32) error // NdirValidator is a validator for the "ndir" field. It is called by the builders before save. NdirValidator func(string) error + // DefaultStr holds the default value on creation for the str field. + DefaultStr func() sql.NullString + // DefaultNullStr holds the default value on creation for the null_str field. + DefaultNullStr func() sql.NullString // LinkValidator is a validator for the "link" field. It is called by the builders before save. LinkValidator func(string) error + // DefaultIP holds the default value on creation for the ip field. + DefaultIP func() net.IP // MACValidator is a validator for the "mac" field. It is called by the builders before save. MACValidator func(string) error ) diff --git a/entc/integration/ent/fieldtype_create.go b/entc/integration/ent/fieldtype_create.go index 461010911..763c98f82 100644 --- a/entc/integration/ent/fieldtype_create.go +++ b/entc/integration/ent/fieldtype_create.go @@ -612,6 +612,18 @@ func (ftc *FieldTypeCreate) SaveX(ctx context.Context) *FieldType { // defaults sets the default values of the builder before save. func (ftc *FieldTypeCreate) defaults() { + if _, ok := ftc.mutation.Str(); !ok { + v := fieldtype.DefaultStr() + ftc.mutation.SetStr(v) + } + if _, ok := ftc.mutation.NullStr(); !ok { + v := fieldtype.DefaultNullStr() + ftc.mutation.SetNullStr(v) + } + if _, ok := ftc.mutation.IP(); !ok { + v := fieldtype.DefaultIP() + ftc.mutation.SetIP(v) + } if _, ok := ftc.mutation.Role(); !ok { v := fieldtype.DefaultRole ftc.mutation.SetRole(v) diff --git a/entc/integration/ent/runtime.go b/entc/integration/ent/runtime.go index 0e609be36..1ae9f7bf4 100644 --- a/entc/integration/ent/runtime.go +++ b/entc/integration/ent/runtime.go @@ -7,8 +7,10 @@ package ent import ( + "net" "time" + "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/entc/integration/ent/card" "github.com/facebook/ent/entc/integration/ent/fieldtype" "github.com/facebook/ent/entc/integration/ent/file" @@ -56,10 +58,22 @@ func init() { fieldtypeDescNdir := fieldtypeFields[27].Descriptor() // fieldtype.NdirValidator is a validator for the "ndir" field. It is called by the builders before save. fieldtype.NdirValidator = fieldtypeDescNdir.Validators[0].(func(string) error) + // fieldtypeDescStr is the schema descriptor for str field. + fieldtypeDescStr := fieldtypeFields[28].Descriptor() + // fieldtype.DefaultStr holds the default value on creation for the str field. + fieldtype.DefaultStr = fieldtypeDescStr.Default.(func() sql.NullString) + // fieldtypeDescNullStr is the schema descriptor for null_str field. + fieldtypeDescNullStr := fieldtypeFields[29].Descriptor() + // fieldtype.DefaultNullStr holds the default value on creation for the null_str field. + fieldtype.DefaultNullStr = fieldtypeDescNullStr.Default.(func() sql.NullString) // fieldtypeDescLink is the schema descriptor for link field. 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) + // fieldtypeDescIP is the schema descriptor for ip field. + fieldtypeDescIP := fieldtypeFields[36].Descriptor() + // fieldtype.DefaultIP holds the default value on creation for the ip field. + fieldtype.DefaultIP = fieldtypeDescIP.Default.(func() net.IP) // 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. diff --git a/entc/integration/ent/schema/fieldtype.go b/entc/integration/ent/schema/fieldtype.go index 82b188455..34e4dddec 100644 --- a/entc/integration/ent/schema/fieldtype.go +++ b/entc/integration/ent/schema/fieldtype.go @@ -79,11 +79,17 @@ func (FieldType) Fields() []ent.Field { GoType(http.Dir("ndir")), field.String("str"). Optional(). - GoType(&sql.NullString{}), + GoType(&sql.NullString{}). + DefaultFunc(func() sql.NullString { + return sql.NullString{String: "default", Valid: true} + }), field.String("null_str"). Optional(). Nillable(). - GoType(&sql.NullString{}), + GoType(&sql.NullString{}). + DefaultFunc(func() sql.NullString { + return sql.NullString{String: "default", Valid: true} + }), field.String("link"). Optional(). NotEmpty(). @@ -107,7 +113,10 @@ func (FieldType) Fields() []ent.Field { GoType(&sql.NullTime{}), field.Bytes("ip"). Optional(). - GoType(net.IP("127.0.0.1")), + GoType(net.IP("127.0.0.1")). + DefaultFunc(func() net.IP { + return net.IP("127.0.0.1") + }), field.Int("null_int64"). Optional(). GoType(&sql.NullInt64{}), diff --git a/entc/integration/gremlin/ent/fieldtype/fieldtype.go b/entc/integration/gremlin/ent/fieldtype/fieldtype.go index 0fd94f4f2..82b43acfd 100644 --- a/entc/integration/gremlin/ent/fieldtype/fieldtype.go +++ b/entc/integration/gremlin/ent/fieldtype/fieldtype.go @@ -7,7 +7,9 @@ package fieldtype import ( + "database/sql" "fmt" + "net" "github.com/facebook/ent/entc/integration/ent/role" ) @@ -118,8 +120,14 @@ var ( ValidateOptionalInt32Validator func(int32) error // NdirValidator is a validator for the "ndir" field. It is called by the builders before save. NdirValidator func(string) error + // DefaultStr holds the default value on creation for the str field. + DefaultStr func() sql.NullString + // DefaultNullStr holds the default value on creation for the null_str field. + DefaultNullStr func() sql.NullString // LinkValidator is a validator for the "link" field. It is called by the builders before save. LinkValidator func(string) error + // DefaultIP holds the default value on creation for the ip field. + DefaultIP func() net.IP // MACValidator is a validator for the "mac" field. It is called by the builders before save. MACValidator func(string) error ) diff --git a/entc/integration/gremlin/ent/fieldtype_create.go b/entc/integration/gremlin/ent/fieldtype_create.go index 4ba4722cd..91f96a03b 100644 --- a/entc/integration/gremlin/ent/fieldtype_create.go +++ b/entc/integration/gremlin/ent/fieldtype_create.go @@ -613,6 +613,18 @@ func (ftc *FieldTypeCreate) SaveX(ctx context.Context) *FieldType { // defaults sets the default values of the builder before save. func (ftc *FieldTypeCreate) defaults() { + if _, ok := ftc.mutation.Str(); !ok { + v := fieldtype.DefaultStr() + ftc.mutation.SetStr(v) + } + if _, ok := ftc.mutation.NullStr(); !ok { + v := fieldtype.DefaultNullStr() + ftc.mutation.SetNullStr(v) + } + if _, ok := ftc.mutation.IP(); !ok { + v := fieldtype.DefaultIP() + ftc.mutation.SetIP(v) + } if _, ok := ftc.mutation.Role(); !ok { v := fieldtype.DefaultRole ftc.mutation.SetRole(v) diff --git a/entc/integration/gremlin/ent/runtime.go b/entc/integration/gremlin/ent/runtime.go index 3c7103f8f..450ace506 100644 --- a/entc/integration/gremlin/ent/runtime.go +++ b/entc/integration/gremlin/ent/runtime.go @@ -7,6 +7,8 @@ package ent import ( + "database/sql" + "net" "time" "github.com/facebook/ent/entc/integration/ent/schema" @@ -56,10 +58,22 @@ func init() { fieldtypeDescNdir := fieldtypeFields[27].Descriptor() // fieldtype.NdirValidator is a validator for the "ndir" field. It is called by the builders before save. fieldtype.NdirValidator = fieldtypeDescNdir.Validators[0].(func(string) error) + // fieldtypeDescStr is the schema descriptor for str field. + fieldtypeDescStr := fieldtypeFields[28].Descriptor() + // fieldtype.DefaultStr holds the default value on creation for the str field. + fieldtype.DefaultStr = fieldtypeDescStr.Default.(func() sql.NullString) + // fieldtypeDescNullStr is the schema descriptor for null_str field. + fieldtypeDescNullStr := fieldtypeFields[29].Descriptor() + // fieldtype.DefaultNullStr holds the default value on creation for the null_str field. + fieldtype.DefaultNullStr = fieldtypeDescNullStr.Default.(func() sql.NullString) // fieldtypeDescLink is the schema descriptor for link field. 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) + // fieldtypeDescIP is the schema descriptor for ip field. + fieldtypeDescIP := fieldtypeFields[36].Descriptor() + // fieldtype.DefaultIP holds the default value on creation for the ip field. + fieldtype.DefaultIP = fieldtypeDescIP.Default.(func() net.IP) // 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. diff --git a/entc/integration/type_test.go b/entc/integration/type_test.go index 035fbc68f..d81c141c2 100644 --- a/entc/integration/type_test.go +++ b/entc/integration/type_test.go @@ -61,8 +61,7 @@ func Types(t *testing.T, client *ent.Client) { SetNillableInt64(math.MinInt64). SetDir("dir"). SetNdir("ndir"). - SetStr(sql.NullString{String: "str", Valid: true}). - SetNullStr(sql.NullString{String: "str", Valid: true}). + SetNullStr(sql.NullString{String: "not-default", Valid: true}). SetLink(schema.Link{URL: link}). SetNullLink(schema.Link{URL: link}). SetRole(role.Admin). @@ -79,10 +78,11 @@ func Types(t *testing.T, client *ent.Client) { require.Equal(http.Dir("dir"), ft.Dir) require.NotNil(*ft.Ndir) require.Equal(http.Dir("ndir"), *ft.Ndir) - require.Equal("str", ft.Str.String) - require.Equal("str", ft.NullStr.String) + require.Equal("default", ft.Str.String) + require.Equal("not-default", ft.NullStr.String) require.Equal("localhost", ft.Link.String()) require.Equal("localhost", ft.NullLink.String()) + require.Equal(net.IP("127.0.0.1").String(), ft.IP.String()) mac, err := net.ParseMAC("3b:b3:6b:3c:10:79") require.NoError(err) dt, err := time.Parse(time.RFC3339, "1906-01-02T00:00:00+00:00") diff --git a/schema/field/field_test.go b/schema/field/field_test.go index 8ac149328..cb2f6fcba 100644 --- a/schema/field/field_test.go +++ b/schema/field/field_test.go @@ -185,9 +185,7 @@ func TestBytes(t *testing.T) { fd = field.Bytes("uuid"). GoType(&uuid.UUID{}). - DefaultFunc(func() uuid.UUID { - return uuid.New() - }). + DefaultFunc(uuid.New). Descriptor() assert.NoError(t, fd.Err) assert.Equal(t, "uuid.UUID", fd.Info.Ident)