Skip to content

Commit cb28a46

Browse files
author
Chris Busbey
committed
only imports decimal package if not using floats, and there are decimal fields
1 parent 7a28360 commit cb28a46

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

cmd/generate-fix/internal/template_helpers.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import (
66
"github.com/quickfixgo/quickfix/datadictionary"
77
)
88

9+
func checkIfDecimalImportRequiredForFields(fTypes []*datadictionary.FieldType) (ok bool, err error) {
10+
var t string
11+
for _, fType := range fTypes {
12+
t, err = quickfixType(fType)
13+
if err != nil {
14+
return
15+
}
16+
17+
if t == "FIXDecimal" {
18+
return true, nil
19+
}
20+
}
21+
22+
return
23+
}
24+
925
func checkFieldDecimalRequired(f *datadictionary.FieldDef) (required bool, err error) {
1026
var globalType *datadictionary.FieldType
1127
if globalType, err = getGlobalFieldType(f); err != nil {
@@ -92,8 +108,6 @@ func collectExtraImports(m *datadictionary.MessageDef) (imports []string, err er
92108
return
93109
}
94110

95-
func useFloatType() bool { return *useFloat }
96-
97111
func quickfixValueType(quickfixType string) (goType string, err error) {
98112
switch quickfixType {
99113
case "FIXString":

cmd/generate-fix/internal/templates.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ var (
1616

1717
func init() {
1818
tmplFuncs := template.FuncMap{
19-
"toLower": strings.ToLower,
20-
"requiredFields": requiredFields,
21-
"beginString": beginString,
22-
"routerBeginString": routerBeginString,
23-
"importRootPath": getImportPathRoot,
24-
"quickfixType": quickfixType,
25-
"quickfixValueType": quickfixValueType,
26-
"getGlobalFieldType": getGlobalFieldType,
27-
"collectExtraImports": collectExtraImports,
28-
"useFloatType": useFloatType,
19+
"toLower": strings.ToLower,
20+
"requiredFields": requiredFields,
21+
"beginString": beginString,
22+
"routerBeginString": routerBeginString,
23+
"importRootPath": getImportPathRoot,
24+
"quickfixType": quickfixType,
25+
"quickfixValueType": quickfixValueType,
26+
"getGlobalFieldType": getGlobalFieldType,
27+
"collectExtraImports": collectExtraImports,
28+
"checkIfDecimalImportRequiredForFields": checkIfDecimalImportRequiredForFields,
2929
}
3030

3131
baseTemplate := template.Must(template.New("Base").Funcs(tmplFuncs).Parse(`
@@ -284,7 +284,7 @@ package field
284284
import(
285285
"github.com/quickfixgo/quickfix"
286286
"{{ importRootPath }}/tag"
287-
{{ if eq useFloatType false}} "github.com/shopspring/decimal" {{ end }}
287+
{{ if checkIfDecimalImportRequiredForFields . }} "github.com/shopspring/decimal" {{ end }}
288288
"time"
289289
)
290290

0 commit comments

Comments
 (0)