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

stiller_leser
<p>Got it to work.</p>
<p>Here's the interace I build:</p>
<pre class="lang-golang prettyprint-override"><code>type MyObject interface {
    metav1.Object
    DeepCopyObject() runtime.Object
    GetObjectKind() schema.ObjectKind
}
</code></pre>
<p>A potential method signature looks like this:</p>
<pre class="lang-golang prettyprint-override"><code>func myFunc(ctx context.Context, client client.Client, object MyObject){}
</code></pre>
<p>Only downside <code>.DeepCopy()</code> will not be available as it returns a specific type and can't be overloaded in the <code>Interface</code>.</p>
