diff --git a/internal/method/reference_processor.go b/internal/method/reference_processor.go index f8e900c..7921ba1 100644 --- a/internal/method/reference_processor.go +++ b/internal/method/reference_processor.go @@ -72,6 +72,9 @@ type Reference struct { // IsFloatPointer tells whether the current value pointer is of type float64 IsFloatPointer bool + + // IsIntPointer tells whether the current value pointer is of type int + IsIntPointer bool } // ReferenceProcessorOption is used to configure ReferenceProcessor. @@ -118,7 +121,6 @@ func (rp *ReferenceProcessor) Process(_ *types.Named, f *types.Var, _, comment s refType := refTypeValues[0] isPointer := false isList := false - isFloatPointer := false refFieldName := f.Name() + "Ref" // We don't support *[]string. @@ -136,9 +138,9 @@ func (rp *ReferenceProcessor) Process(_ *types.Named, f *types.Var, _, comment s } } - if strings.HasSuffix(f.Type().String(), "*float64") { - isFloatPointer = true - } + isFloatPointer := strings.HasSuffix(f.Type().String(), "*float64") + + isIntPointer := strings.HasSuffix(f.Type().String(), "*int64") extractorPath := rp.DefaultExtractor if values, ok := markers[ReferenceExtractorMarker]; ok { @@ -168,6 +170,7 @@ func (rp *ReferenceProcessor) Process(_ *types.Named, f *types.Var, _, comment s IsPointer: isPointer, IsSlice: isList, IsFloatPointer: isFloatPointer, + IsIntPointer: isIntPointer, }) return nil } diff --git a/internal/method/resolver.go b/internal/method/resolver.go index cf66d96..36e5ba1 100644 --- a/internal/method/resolver.go +++ b/internal/method/resolver.go @@ -135,6 +135,10 @@ func singleResolutionCall(ref Reference, referencePkgPath string) resolutionCall toPointerFunction = "ToFloatPtrValue" fromPointerFunction = "FromFloatPtrValue" } + if ref.IsIntPointer { + toPointerFunction = "ToIntPtrValue" + fromPointerFunction = "FromIntPtrValue" + } if ref.IsPointer { setResolvedValue = currentValuePath.Clone().Op("=").Qual(referencePkgPath, toPointerFunction).Call(jen.Id("rsp").Dot("ResolvedValue")) currentValuePath = jen.Qual(referencePkgPath, fromPointerFunction).Call(currentValuePath) @@ -184,6 +188,10 @@ func multiResolutionCall(ref Reference, referencePkgPath string) resolutionCallF toPointersFunction = "ToFloatPtrValues" fromPointersFunction = "FromFloatPtrValues" } + if ref.IsIntPointer { + toPointersFunction = "ToIntPtrValues" + fromPointersFunction = "FromIntPtrValues" + } if ref.IsPointer { setResolvedValues = currentValuePath.Clone().Op("=").Qual(referencePkgPath, toPointersFunction).Call(jen.Id("mrsp").Dot("ResolvedValues"))