Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions examples/different_dir/misc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions examples/misc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions examples/repository/misc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions generator/templates/misc.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ func tagMap(v interface{}) map[string]string {
if firestoreTag, ok := ft.Tag.Lookup("firestore"); ok {
tag = strings.Split(firestoreTag, ",")[0]
}
switch fv.Kind() {
case reflect.Ptr:
ptrType := reflect.PtrTo(fv.Type()).Elem()
if fv.Kind() == reflect.Ptr {
ptrType := reflect.PointerTo(fv.Type()).Elem()
fv = reflect.New(ptrType.Elem())
fallthrough
}
switch fv.Kind() {
case reflect.Struct:
if isReservedType(fv) {
break
Expand Down Expand Up @@ -141,11 +141,12 @@ func updateBuilder(v, param interface{}) map[string]firestore.Update {
pfv.Set(reflect.New(fv.Type().Elem()))
}

switch fv.Kind() {
case reflect.Ptr:
ptrType := reflect.PtrTo(fv.Type()).Elem()
if fv.Kind() == reflect.Ptr {
ptrType := reflect.PointerTo(fv.Type()).Elem()
fv = reflect.New(ptrType.Elem())
fallthrough
}

switch fv.Kind() {
case reflect.Struct:
if isReservedType(fv) {
break
Expand Down
17 changes: 9 additions & 8 deletions generator/testfiles/auto/misc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions generator/testfiles/misc/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func tagMap(v interface{}) map[string]string {
if firestoreTag, ok := ft.Tag.Lookup("firestore"); ok {
tag = strings.Split(firestoreTag, ",")[0]
}
switch fv.Kind() {
case reflect.Ptr:
ptrType := reflect.PtrTo(fv.Type()).Elem()
if fv.Kind() == reflect.Ptr {
ptrType := reflect.PointerTo(fv.Type()).Elem()
fv = reflect.New(ptrType.Elem())
fallthrough
}
switch fv.Kind() {
case reflect.Struct:
if isReservedType(fv) {
break
Expand Down Expand Up @@ -109,12 +109,11 @@ func updateBuilder(v, param interface{}) map[string]firestore.Update {
}

pfv := pv.FieldByName(ft.Name)

switch fv.Kind() {
case reflect.Ptr:
ptrType := reflect.PtrTo(fv.Type()).Elem()
if fv.Kind() == reflect.Ptr {
ptrType := reflect.PointerTo(fv.Type()).Elem()
fv = reflect.New(ptrType.Elem())
fallthrough
}
switch fv.Kind() {
case reflect.Struct:
if isReservedType(fv) {
break
Expand Down
15 changes: 10 additions & 5 deletions generator/testfiles/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ type article struct {
}

type user struct {
Name string `json:"name" firestore:"name"`
Age int `json:"age" firestore:"age"`
BirthDay *time.Time `json:"birthDay" firestore:"birthDay"`
IsAdult bool `json:"isAdult" firestore:"isAdult"`
Address address `json:"address" firestore:"address"`
Name string `json:"name" firestore:"name"`
Age int `json:"age" firestore:"age"`
BirthDay *time.Time `json:"birthDay" firestore:"birthDay"`
IsAdult bool `json:"isAdult" firestore:"isAdult"`
Address address `json:"address" firestore:"address"`
Occupation *string `json:"occupation" firestore:"occupation"`
}

type address struct {
Expand Down Expand Up @@ -64,6 +65,7 @@ func Test_updateBuilder(t *testing.T) {
Latitude: 35.678803,
Longitude: 139.756263,
}
occupation := "engineer"

tests := []struct {
name string
Expand All @@ -82,6 +84,7 @@ func Test_updateBuilder(t *testing.T) {
Address: address{
LatLng: latLng,
},
Occupation: &occupation,
},
Page: "section",
Published: false,
Expand All @@ -96,6 +99,7 @@ func Test_updateBuilder(t *testing.T) {
"user.Age": {FieldPath: firestore.FieldPath{"user", "age"}, Value: age},
"user.BirthDay": {FieldPath: firestore.FieldPath{"user", "birthDay"}, Value: &unix},
"user.address.LatLng": {FieldPath: firestore.FieldPath{"user", "address", "LatLng"}, Value: latLng},
"user.Occupation": {FieldPath: firestore.FieldPath{"user", "occupation"}, Value: &occupation},
"Page": {FieldPath: firestore.FieldPath{"page"}, Value: "section"},
"Published": {FieldPath: firestore.FieldPath{"published"}, Value: false},
"CreatedAt": {FieldPath: firestore.FieldPath{"createdAt"}, Value: unix},
Expand Down Expand Up @@ -222,6 +226,7 @@ func Test_tagMap(t *testing.T) {
"user.IsAdult": "user.isAdult",
"user.Name": "user.name",
"user.address.LatLng": "user.address.LatLng",
"user.Occupation": "user.occupation",
},
},
}
Expand Down
17 changes: 9 additions & 8 deletions generator/testfiles/not_auto/misc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.