From 74ada3e1ca1c72f39459fcdecb906fc42f1746a7 Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Mon, 20 Nov 2023 14:48:58 -0500 Subject: [PATCH] add support for int pointer values for references Signed-off-by: Evan Johnson --- internal/method/reference_processor.go | 11 +++++++---- internal/method/resolver.go | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) 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"))