<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrey M.</title>
    <description>The latest articles on DEV Community by Andrey M. (@andrey_m).</description>
    <link>https://dev.to/andrey_m</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4101118%2Fad70d9c9-9376-429a-bd93-f366bab3aa59.jpg</url>
      <title>DEV Community: Andrey M.</title>
      <link>https://dev.to/andrey_m</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andrey_m"/>
    <language>en</language>
    <item>
      <title>It's just HTTP, so it's just Go: a bit-perfect UPnP player, one codebase for Windows, Linux and macOS</title>
      <dc:creator>Andrey M.</dc:creator>
      <pubDate>Sun, 15 Nov 2026 12:24:55 +0000</pubDate>
      <link>https://dev.to/andrey_m/taking-the-pc-out-of-the-audio-path-a-bit-perfect-upnp-player-in-go-and-a-week-of-fighting-ggd</link>
      <guid>https://dev.to/andrey_m/taking-the-pc-out-of-the-audio-path-a-bit-perfect-upnp-player-in-go-and-a-week-of-fighting-ggd</guid>
      <description>&lt;p&gt;I listen to a lossless library, FLAC files and whole-album FLAC images with &lt;code&gt;.cue&lt;/code&gt; sheets, through two small network streamers. For a while I drove them from foobar2000: install the UPnP component, pick the renderer as the output, choose the format it should be sent, keep the DSP chain empty so the samples arrive untouched, restart playback after every change. It works, but it is a ritual.&lt;/p&gt;

&lt;p&gt;Then it dawned on me what a UPnP renderer actually is: an HTTP client. You tell it, in a small SOAP request, "play this URL", and it comes to you for the bytes with a plain GET. No driver sits in between, no output plugin, nothing to install on either side. Everything else is settings around an HTTP download.&lt;/p&gt;

&lt;p&gt;And if it is only HTTP, nothing ties the player to one OS. So I wrote it in Go, as a single codebase that runs on Windows, Linux and macOS: one binary that finds the streamers on the home network, serves them the music itself and has nothing to configure.&lt;/p&gt;

&lt;p&gt;This is the story of why a streamer in the first place, and of what two small boxes taught me about UPnP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a streamer and not a USB DAC
&lt;/h2&gt;

&lt;p&gt;USB ties the DAC to the computer's ground, and with it to the noise of switching power supplies, a graphics card and fans. Ethernet carries only data and is isolated by transformers.&lt;/p&gt;

&lt;p&gt;A streamer is a small box with nothing else to do. It buffers the stream at its leisure (music, unlike games, does not care whether a track starts 5 ms or half a second after Play) and feeds the DAC, which clocks the samples out by its own oscillator. The computer is out of the picture.&lt;/p&gt;

&lt;p&gt;I have two of them, both running &lt;a href="https://github.com/hzeller/gmrender-resurrect" rel="noopener noreferrer"&gt;gmrender-resurrect&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a home-made one, a BeagleBone Green with a USB DAC;&lt;/li&gt;
&lt;li&gt;a FiiO SR11.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both speak UPnP/DLNA.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "bit-perfect" means here
&lt;/h2&gt;

&lt;p&gt;The player decodes FLAC on the PC and sends the streamer the original samples as WAV: no resampling, no dither, no volume applied on the way. Two things change samples, and only when they apply:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the 18-band equalizer, while it is on (it reads foobar2000 &lt;code&gt;.feq&lt;/code&gt; presets);&lt;/li&gt;
&lt;li&gt;a 10 ms fade-in where a stream starts mid-wave (Play, a seek), so music cut in the middle of a waveform does not click. foobar2000 does the same after a seek.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tracks that follow one another are never touched.&lt;/p&gt;

&lt;p&gt;Lossy formats are not supported and will not be. A link built for bit-perfect sound has no use for MP3.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture is boring on purpose
&lt;/h2&gt;

&lt;p&gt;It is one Go binary (Fiber v3) with a React page embedded in it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSDP&lt;/strong&gt; finds the renderers; their device descriptions say which MIME types they take.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SOAP&lt;/strong&gt; drives them: &lt;code&gt;SetAVTransportURI&lt;/code&gt;, &lt;code&gt;Play&lt;/code&gt;, &lt;code&gt;Pause&lt;/code&gt;, &lt;code&gt;Seek&lt;/code&gt;, &lt;code&gt;Stop&lt;/code&gt;, and polls &lt;code&gt;GetTransportInfo&lt;/code&gt; + &lt;code&gt;GetPositionInfo&lt;/code&gt; once a second.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP&lt;/strong&gt; serves the music: the renderer is told "play this URL" and comes back for the bytes, with Range requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSE&lt;/strong&gt; pushes the state to the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A CUE track has no file of its own, so it is served as a virtual WAV: a 44-byte header plus the PCM of its sample range, decoded on the fly, with Range support so the renderer can seek.&lt;/p&gt;

&lt;p&gt;Because the whole exchange is plain HTTP and UPnP, the same binary runs wherever Go builds. It is tested on Windows, Linux and macOS 12. On Windows it installs with a window of its own (WebView2). Anywhere else the UI is the browser, and from a phone the same page is a remote.&lt;/p&gt;

&lt;p&gt;That was the easy part. Then the streamers started having opinions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 1: the renderer's position is a rumour
&lt;/h2&gt;

&lt;p&gt;The obvious design is "the player keeps a model of what the renderer is doing". It does not survive contact with gmrender:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;TrackURI&lt;/code&gt; jumps to the next track minutes early&lt;/strong&gt;, as soon as GStreamer has buffered the current WAV. Taken at its word, the playlist advances while the old song still plays.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Seek&lt;/code&gt; answers OK at once&lt;/strong&gt;, but &lt;code&gt;RelTime&lt;/code&gt; stays at the old place for half a second, or over a second for a jump of minutes in a long stream. A click on track 17 polled as "still on track 15", and the player helpfully "corrected" the playlist.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A &lt;code&gt;Seek&lt;/code&gt; in the first moments of a stream is silently ignored.&lt;/strong&gt; OK, and it keeps playing from 0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Now and then it reports &lt;code&gt;0:00:00&lt;/code&gt;&lt;/strong&gt; far behind where it actually plays.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these got its own fix (one odd report is not acted on, the same one twice is; a start at a position is a stream that &lt;em&gt;begins&lt;/em&gt; there instead of a seek). But the real lesson came later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 2: clicks on the coaxial output
&lt;/h2&gt;

&lt;p&gt;The FiiO's coaxial output clicked at track boundaries. Its USB output to the same DAC was silent.&lt;/p&gt;

&lt;p&gt;I measured before guessing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The served audio was clean at the boundary: the last samples of one track and the first of the next differed by 1–7 out of 32768.&lt;/li&gt;
&lt;li&gt;The player answered in 3–5 ms.&lt;/li&gt;
&lt;li&gt;The FiiO, though, read the current stream to the end 5 s early and opened the next URI only at the last second. Its output buffer ran dry for a moment, the S/PDIF receiver lost lock, click.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The cure was to stop giving it boundaries: the tracks of one format (rate, channels, bits) go as &lt;strong&gt;one continuous WAV stream&lt;/strong&gt;, the way foobar2000 sends them. A jump to another track of the album is a seek in that stream. The player keeps the layout and turns the stream position back into "track 7, 2:13" for the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 3: I tried to be clever, and it hung
&lt;/h2&gt;

&lt;p&gt;Early on the FiiO took its whole UPnP service down on a &lt;code&gt;Stop&lt;/code&gt;, until a power cycle. So the player stopped sending &lt;code&gt;Stop&lt;/code&gt; at all. Tracks were switched through the gapless path instead (&lt;code&gt;SetNextAVTransportURI&lt;/code&gt;, then a seek to the end of the current stream), the Stop button became a pause, and the end of a playlist left the renderer paused at the last second.&lt;/p&gt;

&lt;p&gt;It worked, mostly. Then, one after another:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The BeagleBone started &lt;em&gt;racing&lt;/em&gt;: PLAYING, no sound, position running at 5–40x real time. Only &lt;code&gt;Stop → SetAVTransportURI → Play&lt;/code&gt; cured it, which is exactly what foobar2000 always sends.&lt;/li&gt;
&lt;li&gt;A played-out FiiO sat at 37:37 of 37:37, accepted Seek and Play without an error, and moved nowhere. The next start hung.&lt;/li&gt;
&lt;li&gt;The BeagleBone hung on the clever switch path three times in a row.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every workaround had bred the next bug. So I threw them out and wrote down a rule instead:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Stop is Stop&lt;/strong&gt;, on every renderer. Ask the renderer its state first. If it already reports STOPPED, send nothing. Otherwise send one &lt;code&gt;Stop&lt;/code&gt;, never repeated, and then only poll until it reports STOPPED. Every next step is sent only once the renderer has reported the previous one done.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No delays, no silence windows, no special cases per model. The end of the playlist stops the renderer, as foobar2000 does. A start from STOPPED is a plain new stream at the chosen track. The page shows the state the renderer reports, never what the player &lt;em&gt;intends&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The hangs went away together with the workarounds. In hindsight that's not surprising: the parallel realities the player kept in its head were the bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 4: measure with your ears, systematically
&lt;/h2&gt;

&lt;p&gt;Some of this could only be heard. For the click hunt I added a temporary "mark" button and pressed it on every click while doing a dozen random Next / Prev / track clicks. The marks lined up exactly with jumps that needed a new stream and never with seeks inside one. That settled an argument the logs could not.&lt;/p&gt;

&lt;p&gt;Every decision like this is written down as an ADR in the repository, with the options that were rejected and the measurement that decided it. There are 27 of them now. Half are a field guide to gmrender's behaviour.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Windows: a per-user setup or a zip from &lt;a href="https://github.com/panedrone/go-upnp-player/releases" rel="noopener noreferrer"&gt;Releases&lt;/a&gt;, no administrator rights.&lt;/li&gt;
&lt;li&gt;Linux and macOS: &lt;code&gt;go install github.com/panedrone/go-upnp-player/cmd/go-upnp-player@latest&lt;/code&gt; (on macOS 12, use Go 1.26 and &lt;code&gt;CGO_ENABLED=0&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source, docs and all the ADRs: &lt;strong&gt;&lt;a href="https://github.com/panedrone/go-upnp-player" rel="noopener noreferrer"&gt;github.com/panedrone/go-upnp-player&lt;/a&gt;&lt;/strong&gt; (ISC license).&lt;/p&gt;

&lt;p&gt;If you have a streamer that is not gmrender-based, I would love to hear how it behaves.&lt;/p&gt;

</description>
      <category>go</category>
      <category>music</category>
      <category>opensource</category>
      <category>showdev</category>
    </item>
    <item>
      <title>I stopped diffing my Go structs against the schema by hand. Now CI does it.</title>
      <dc:creator>Andrey M.</dc:creator>
      <pubDate>Wed, 14 Oct 2026 13:51:16 +0000</pubDate>
      <link>https://dev.to/andrey_m/i-stopped-diffing-my-go-structs-against-the-schema-by-hand-now-ci-does-it-5db4</link>
      <guid>https://dev.to/andrey_m/i-stopped-diffing-my-go-structs-against-the-schema-by-hand-now-ci-does-it-5db4</guid>
      <description>&lt;p&gt;A while ago I wrote about &lt;a href="https://dev.to/andrey_m/a-column-changed-type-8-days-after-i-mapped-it-and-nothing-told-me-5a2n"&gt;a column that changed type 8 days after I mapped it&lt;/a&gt;. &lt;code&gt;int NOT NULL&lt;/code&gt; became &lt;code&gt;decimal(19,2) NULL&lt;/code&gt;, my hand-written struct still said &lt;code&gt;int64&lt;/code&gt;, and nothing complained. The fix back then was to point a code generator at the live database and diff its output against what I had.&lt;/p&gt;

&lt;p&gt;That worked. It also had a weak spot I didn't want to admit: &lt;em&gt;I&lt;/em&gt; had to remember to run it. The generator lived in an IDE plug-in and talked to the database over JDBC. Great on my machine, useless in a pipeline. A check that depends on a human remembering it is a check that runs on good days.&lt;/p&gt;

&lt;p&gt;So I rewrote the generator in Go.&lt;/p&gt;

&lt;h2&gt;
  
  
  One binary, no JVM
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;install &lt;/span&gt;github.com/panedrone/go-sdm/cmd/sdm@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's called &lt;code&gt;go-sdm&lt;/code&gt;. One static binary, no runtime dependencies, PostgreSQL, MySQL and SQLite. Same idea as before: an XML manifest says &lt;em&gt;what&lt;/em&gt; to generate, the live database says &lt;em&gt;what it actually looks like&lt;/em&gt;, and the generator writes the models and DAO in Go.&lt;/p&gt;

&lt;p&gt;The part that matters for this story is one command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sdm val
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It generates everything in memory, compares it with the files in the repo, and exits &lt;code&gt;1&lt;/code&gt; if anything differs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;out of date: internal/dbal/models/asset.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the whole trick. If someone runs a migration and nobody regenerates, the build goes red. Not three weeks later as "why is this value off by a few cents" — on the next push.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# GitHub Actions, roughly&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;go install github.com/panedrone/go-sdm/cmd/sdm@latest&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;sdm val&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;SDM_PWD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DB_PASSWORD }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The honest caveat: &lt;code&gt;sdm val&lt;/code&gt; needs a database to read. I don't parse DDL, on purpose — the database knows things the DDL doesn't show: views, the real column types of a query's result set, procedure parameters, ref-cursors. So CI needs a reachable database with the current schema: a staging one, or a container you migrate right before the check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting from an existing database
&lt;/h2&gt;

&lt;p&gt;The first post was about a DB-first rewrite: eighteen tables already there, nobody planning to redesign them. Writing the manifest by hand for that is exactly the kind of busywork that makes people skip the whole idea. So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sdm xml &lt;span class="nt"&gt;-orm&lt;/span&gt; sqlx &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; start.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;reads every table and view and prints a starting manifest: a model per table and a DAO per table, named after it, with CRUD and the lookups by foreign key already in place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dto-class&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"sqlx-Task"&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"tasks"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dao-class&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"TasksDao"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;crud&lt;/span&gt; &lt;span class="na"&gt;dto=&lt;/span&gt;&lt;span class="s"&gt;"sqlx-Task"&lt;/span&gt; &lt;span class="na"&gt;table=&lt;/span&gt;&lt;span class="s"&gt;"tasks"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;query-dto-list&lt;/span&gt; &lt;span class="na"&gt;dto=&lt;/span&gt;&lt;span class="s"&gt;"sqlx-Task"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"getTasksByGroup(gID)"&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"tasks(g_id)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dao-class&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it again after a new table appears and it prints only the new one — whatever is already in the manifest is skipped. &lt;code&gt;-orm&lt;/code&gt; picks plain &lt;code&gt;database/sql&lt;/code&gt;, &lt;code&gt;sqlx&lt;/code&gt; or &lt;code&gt;gorm&lt;/code&gt; for the models, and it's required on purpose: I'd rather type six characters than find out later that a default chose for me.&lt;/p&gt;

&lt;p&gt;This week I pointed it at a Postgres database with 21 tables: one command for the manifest, one &lt;code&gt;sdm gen&lt;/code&gt;, and the data layer compiled. Most of the time went into reading the output.&lt;/p&gt;

&lt;h2&gt;
  
  
  DAO as variables, not structs
&lt;/h2&gt;

&lt;p&gt;One more thing I changed compared to the usual generated DAO. There's no repository struct to construct and pass around, and no interface to mock. Each DAO function is a package-level variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;GetTestRating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tID&lt;/span&gt; &lt;span class="kt"&gt;int32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A unit test swaps the one it needs and puts it back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;saved&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;dbal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetTestRating&lt;/span&gt;
&lt;span class="n"&gt;dbal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetTestRating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tID&lt;/span&gt; &lt;span class="kt"&gt;int32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;4.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Cleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;dbal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetTestRating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;saved&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No mocking library, no database in unit tests. The database shows up exactly once — in &lt;code&gt;sdm val&lt;/code&gt;, which is the one place where it's supposed to be the source of truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  The point, again
&lt;/h2&gt;

&lt;p&gt;Last time the conclusion was: stop hand-maintaining the mapping between a table and a struct, regenerate it from the table. This time it's the second half of that sentence: &lt;strong&gt;and make the build fail when you forget.&lt;/strong&gt; A generator you have to remember to run is just a nicer way to hand-maintain things.&lt;/p&gt;

&lt;p&gt;go-sdm is here: &lt;a href="https://github.com/panedrone/go-sdm" rel="noopener noreferrer"&gt;github.com/panedrone/go-sdm&lt;/a&gt;. A working example with a generated data layer: &lt;a href="https://github.com/panedrone/sdm_todolist_go_react_vue_npm_sqlite3" rel="noopener noreferrer"&gt;sdm_todolist_go_react_vue_npm_sqlite3&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>go</category>
      <category>postgres</category>
      <category>database</category>
      <category>backend</category>
    </item>
    <item>
      <title>A column changed type 8 days after I mapped it, and nothing told me</title>
      <dc:creator>Andrey M.</dc:creator>
      <pubDate>Sun, 30 Aug 2026 07:59:36 +0000</pubDate>
      <link>https://dev.to/andrey_m/a-column-changed-type-8-days-after-i-mapped-it-and-nothing-told-me-5a2n</link>
      <guid>https://dev.to/andrey_m/a-column-changed-type-8-days-after-i-mapped-it-and-nothing-told-me-5a2n</guid>
      <description>&lt;p&gt;I was rewriting a Java/Spring backend to Go. The database wasn't going anywhere — it&lt;br&gt;
already existed, with real data in it, and eighteen tables' worth of history behind it.&lt;br&gt;
The plan was simple: keep the schema, replace the service layer.&lt;/p&gt;

&lt;p&gt;Early on, &lt;code&gt;asset&lt;/code&gt; looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;`asset`&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;`id`&lt;/span&gt;    &lt;span class="nb"&gt;bigint&lt;/span&gt;       &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="n"&gt;AUTO_INCREMENT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nv"&gt;`value`&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;          &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;`id`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I mapped it to a Go struct by hand, the way you do when you're moving fast and the table&lt;br&gt;
is right there on the screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Asset&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ID&lt;/span&gt;    &lt;span class="kt"&gt;int64&lt;/span&gt;
    &lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eight days later, a migration I wasn't looking at changed it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;`asset`&lt;/span&gt;
    &lt;span class="n"&gt;CHANGE&lt;/span&gt; &lt;span class="nv"&gt;`value`&lt;/span&gt; &lt;span class="nv"&gt;`value`&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;int NOT NULL&lt;/code&gt; became &lt;code&gt;decimal(19,2) NULL&lt;/code&gt;. Two changes at once, and my hand-written&lt;br&gt;
struct still said &lt;code&gt;int64&lt;/code&gt;, no pointer, no way to represent NULL. Nothing failed loudly —&lt;br&gt;
GORM will happily scan a decimal into an int64 and either round it or blow up on a NULL,&lt;br&gt;
depending on the day. It's the kind of bug that shows up as "why is this value off by a&lt;br&gt;
few cents" three weeks later, not as a compile error.&lt;/p&gt;

&lt;p&gt;That's when it clicked: I don't need a unit test for "does my Go struct still match the&lt;br&gt;
&lt;code&gt;asset&lt;/code&gt; table." I need something that reads the table and &lt;em&gt;tells&lt;/em&gt; me if it doesn't.&lt;/p&gt;

&lt;p&gt;So instead of writing the struct by hand, I pointed a small code generator I'd built for&lt;br&gt;
exactly this — reads live schema over JDBC, spits out Go structs — at the same database,&lt;br&gt;
and diffed the output against what I had. It caught &lt;code&gt;value&lt;/code&gt; immediately: wrong type,&lt;br&gt;
wrong nullability, no compile error to warn me.&lt;/p&gt;

&lt;p&gt;None of this is exotic. If you're doing DB-first Go with GORM, this is just what happens&lt;br&gt;
when the schema evolves and your structs are maintained by hand, by a human, on a Tuesday.&lt;br&gt;
The fix isn't "write more tests" — it's "stop hand-maintaining the mapping between a table&lt;br&gt;
and a struct, and regenerate it from the table instead." A unit test only catches what you&lt;br&gt;
thought to test. A schema read catches what actually changed.&lt;/p&gt;

&lt;p&gt;I ended up formalizing this into &lt;a href="https://github.com/panedrone/sqldalmaker" rel="noopener noreferrer"&gt;SQL DAL Maker&lt;/a&gt;&lt;br&gt;
— it reads live JDBC metadata and generates the DAO/model layer for Go (and a few other&lt;br&gt;
languages) from it, so the struct-vs-schema gap can't quietly reopen every time someone&lt;br&gt;
runs a migration. But the generator isn't really the point of this post. The point is:&lt;br&gt;
if your models are hand-typed and your schema isn't frozen, you already have this bug&lt;br&gt;
somewhere. You just haven't hit it yet.&lt;/p&gt;

</description>
      <category>go</category>
      <category>mysql</category>
      <category>gorm</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
