diff --git a/pkg/database/calls.sql.go b/pkg/database/calls.sql.go index 3750009..45d1702 100644 --- a/pkg/database/calls.sql.go +++ b/pkg/database/calls.sql.go @@ -108,7 +108,7 @@ type AddCallParams struct { Frequency int `json:"frequency"` Frequencies []int `json:"frequencies"` Patches []int `json:"patches"` - TalkerAlias *string `json:"talkerAlias"` + TalkerAlias *string `json:"talkerAlias,omitempty"` TGLabel *string `json:"tgLabel"` TGAlphaTag *string `json:"tgAlphaTag"` TGGroup *string `json:"tgGroup"` @@ -205,7 +205,7 @@ type GetCallRow struct { Frequency int `json:"frequency"` Frequencies []int `json:"frequencies"` Patches []int `json:"patches"` - TalkerAlias *string `json:"talkerAlias"` + TalkerAlias *string `json:"talkerAlias,omitempty"` TGLabel *string `json:"tgLabel"` TGAlphaTag *string `json:"tgAlphaTag"` TGGroup *string `json:"tgGroup"` @@ -401,8 +401,8 @@ type ListCallsPRow struct { Duration *int32 `json:"duration"` SystemID int `json:"systemId"` TGID int `json:"tgid"` - TalkerAlias *string `json:"talkerAlias"` - Incidents int64 `json:"incidents"` + TalkerAlias *string `json:"talkerAlias,omitempty"` + Incidents int64 `json:"incidents,omitempty"` } func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListCallsPRow, error) { diff --git a/util/omitempty/omitempty.go b/util/omitempty/omitempty.go index 325d526..4ecc0af 100644 --- a/util/omitempty/omitempty.go +++ b/util/omitempty/omitempty.go @@ -12,10 +12,46 @@ import ( "strings" ) -const filePath = "./pkg/database/models.go" +type FileMap map[string]FieldDecider + +var filePaths = FileMap{ + "./pkg/database/models.go": AllFields{}, + "./pkg/database/calls.sql.go": FieldMap{ + "TalkerAlias": true, + "Incidents": true, + }, +} + +type FieldDecider interface { + Check(fields []*ast.Ident) bool +} + +type FieldMap map[string]bool + +func (fm FieldMap) Check(f []*ast.Ident) bool { + for _, v := range f { + if v != nil && fm[v.Name] { + return true + } + } + + return false +} + +type AllFields struct{} + +func (AllFields) Check(_ []*ast.Ident) bool { + return true +} func main() { // Parse the source code + for k, v := range filePaths { + process(k, v) + } +} + +func process(filePath string, fd FieldDecider) { fset := token.NewFileSet() f, err := parser.ParseFile(fset, filePath, nil, parser.ParseComments) if err != nil { @@ -27,6 +63,9 @@ func main() { switch x := n.(type) { case *ast.StructType: for _, field := range x.Fields.List { + if !fd.Check(field.Names) { + continue + } if field.Tag == nil { continue }