Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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