<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Generics - Tag - Office Hours</title><link>https://titpetric.com/tags/generics/</link><description>Generics - Tag - Office Hours</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>me@titpetric.com (Tit Petric)</managingEditor><webMaster>me@titpetric.com (Tit Petric)</webMaster><copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright><lastBuildDate>Tue, 09 Jun 2026 18:00:00 +0200</lastBuildDate><atom:link href="https://titpetric.com/tags/generics/" rel="self" type="application/rss+xml"/><item><title>Implementation contracts in Go</title><link>https://titpetric.com/2026/06/09/implementation-contracts-in-go/</link><pubDate>Tue, 09 Jun 2026 18:00:00 +0200</pubDate><author>Tit Petric</author><guid>https://titpetric.com/2026/06/09/implementation-contracts-in-go/</guid><description><![CDATA[<p>For a long time, I considered a filled <code>interface</code> type as an
implementation contract in Go. A very quick shorthand on how you can
check for implementation compliance is to add the following snippet to
your <code>_test.go</code> files:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-go">
        <span class="code-title"><i class="arrow fas fa-angle-right fa-fw" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h fa-fw" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy fa-fw" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">_</span> <span class="nx">rpc</span><span class="p">.</span><span class="nx">UserService</span> <span class="p">=</span> <span class="o">&amp;</span><span class="nx">UserService</span><span class="p">{}</span></span></span></code></pre></div></div>
<p>Until your UserService meets the interface contract, the test will
result in failure. You&rsquo;re likely to add this check to ensure your
API is decoupled and can be used behind that interface.</p>]]></description></item></channel></rss>