Skip to content

Commit

Permalink
Remove "omitempty" from Double/Int/Boolean. (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbdavis authored and mickeyreiss committed Nov 17, 2018
1 parent f37bd29 commit a9fe647
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 16 additions & 1 deletion langs/go/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@ func (m *GoModeler) packageName() string {
return m.pkg
}

func (m *GoModeler) fieldTags(field *firemodel.SchemaField) string {
switch field.Type.(type) {
// "false" and "0" should be written
case *firemodel.Boolean,
*firemodel.Integer,
*firemodel.Double:
return strcase.ToLowerCamel(field.Name)

default:
return strcase.ToLowerCamel(field.Name) + ",omitempty"
}

}

func (m *GoModeler) fields(structName string, fields []*firemodel.SchemaField, addTimestampFields bool) func(g *jen.Group) {
return func(g *jen.Group) {
for _, field := range fields {
Expand All @@ -414,10 +428,11 @@ func (m *GoModeler) fields(structName string, fields []*firemodel.SchemaField, a
} else {
g.Comment(field.Comment)
}

g.
Id(strcase.ToCamel(field.Name)).
Do(m.goType(field.Type)).
Tag(map[string]string{"firestore": strcase.ToLowerCamel(field.Name) + ",omitempty"})
Tag(map[string]string{"firestore": m.fieldTags(field)})
}
if addTimestampFields {
g.Line()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type TestModel struct {
// The name.
Name string `firestore:"name,omitempty"`
// The age.
Age int64 `firestore:"age,omitempty"`
Age int64 `firestore:"age"`
// The number pi.
Pi float64 `firestore:"pi,omitempty"`
Pi float64 `firestore:"pi"`
// The birth date.
Birthdate time.Time `firestore:"birthdate,omitempty"`
// True if it is good.
IsGood bool `firestore:"isGood,omitempty"`
IsGood bool `firestore:"isGood"`
// TODO: Add comment to TestModel.data.
Data []byte `firestore:"data,omitempty"`
// TODO: Add comment to TestModel.friend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type TestStruct struct {
// TODO: Add comment to TestStruct.where.
Where string `firestore:"where,omitempty"`
// TODO: Add comment to TestStruct.how_much.
HowMuch int64 `firestore:"howMuch,omitempty"`
HowMuch int64 `firestore:"howMuch"`
// TODO: Add comment to TestStruct.some_enum.
SomeEnum TestEnum `firestore:"someEnum,omitempty"`
}

0 comments on commit a9fe647

Please sign in to comment.