Skip to content

Commit 74ada3e

Browse files
committed
add support for int pointer values for references
Signed-off-by: Evan Johnson <[email protected]>
1 parent 628280f commit 74ada3e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

internal/method/reference_processor.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ type Reference struct {
7272

7373
// IsFloatPointer tells whether the current value pointer is of type float64
7474
IsFloatPointer bool
75+
76+
// IsIntPointer tells whether the current value pointer is of type int
77+
IsIntPointer bool
7578
}
7679

7780
// ReferenceProcessorOption is used to configure ReferenceProcessor.
@@ -118,7 +121,6 @@ func (rp *ReferenceProcessor) Process(_ *types.Named, f *types.Var, _, comment s
118121
refType := refTypeValues[0]
119122
isPointer := false
120123
isList := false
121-
isFloatPointer := false
122124
refFieldName := f.Name() + "Ref"
123125

124126
// We don't support *[]string.
@@ -136,9 +138,9 @@ func (rp *ReferenceProcessor) Process(_ *types.Named, f *types.Var, _, comment s
136138
}
137139
}
138140

139-
if strings.HasSuffix(f.Type().String(), "*float64") {
140-
isFloatPointer = true
141-
}
141+
isFloatPointer := strings.HasSuffix(f.Type().String(), "*float64")
142+
143+
isIntPointer := strings.HasSuffix(f.Type().String(), "*int64")
142144

143145
extractorPath := rp.DefaultExtractor
144146
if values, ok := markers[ReferenceExtractorMarker]; ok {
@@ -168,6 +170,7 @@ func (rp *ReferenceProcessor) Process(_ *types.Named, f *types.Var, _, comment s
168170
IsPointer: isPointer,
169171
IsSlice: isList,
170172
IsFloatPointer: isFloatPointer,
173+
IsIntPointer: isIntPointer,
171174
})
172175
return nil
173176
}

internal/method/resolver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func singleResolutionCall(ref Reference, referencePkgPath string) resolutionCall
135135
toPointerFunction = "ToFloatPtrValue"
136136
fromPointerFunction = "FromFloatPtrValue"
137137
}
138+
if ref.IsIntPointer {
139+
toPointerFunction = "ToIntPtrValue"
140+
fromPointerFunction = "FromIntPtrValue"
141+
}
138142
if ref.IsPointer {
139143
setResolvedValue = currentValuePath.Clone().Op("=").Qual(referencePkgPath, toPointerFunction).Call(jen.Id("rsp").Dot("ResolvedValue"))
140144
currentValuePath = jen.Qual(referencePkgPath, fromPointerFunction).Call(currentValuePath)
@@ -184,6 +188,10 @@ func multiResolutionCall(ref Reference, referencePkgPath string) resolutionCallF
184188
toPointersFunction = "ToFloatPtrValues"
185189
fromPointersFunction = "FromFloatPtrValues"
186190
}
191+
if ref.IsIntPointer {
192+
toPointersFunction = "ToIntPtrValues"
193+
fromPointersFunction = "FromIntPtrValues"
194+
}
187195

188196
if ref.IsPointer {
189197
setResolvedValues = currentValuePath.Clone().Op("=").Qual(referencePkgPath, toPointersFunction).Call(jen.Id("mrsp").Dot("ResolvedValues"))

0 commit comments

Comments
 (0)