Skip to content

Commit

Permalink
add support for int pointer values for references
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Johnson <[email protected]>
  • Loading branch information
eljohnson92 committed Nov 20, 2023
1 parent 628280f commit 74ada3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/method/reference_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions internal/method/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 74ada3e

Please sign in to comment.