I need help with method re-usage in Go.
I have two function signatures in my Kubernetes operator (in different controllers):
func myFunc(ctx context.Context, r *MyKindReconciler, myKind *myApiVersion.myKind) (ctrl.Result, error) {
and
func myFunc(ctx context.Context, r *MyOtherKindReconciler, myOtherKind *myApiVersion.myOtherKind) (ctrl.Result, error) {
The body of the function myFunc
is the same in both cases, only the types of the variables that are passed in are different. Both kinds
have the same methods available.
In order to prevent duplication, I’d like to move this method to a helper if possible. Any idea how this can be achieved?