<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Oskar Höstlund — Learning</title>
    <link>https://www.hostlund.com/learning/</link>
    <description>Software engineer in Berlin. Core banking interfaces, FinTS, and Java systems, after earlier work in technology strategy.</description>
    <atom:link href="https://www.hostlund.com/rss.xml" rel="self" type="application/rss+xml"/>
    <lastBuildDate>Sat, 28 Nov 2026 15:11:51 GMT</lastBuildDate>
    <item>
      <title>Using the Go programming language on this site: the camt and pain readers</title>
      <link>https://www.hostlund.com/learning/go-on-this-site/</link>
      <guid isPermaLink="true">https://www.hostlund.com/learning/go-on-this-site/</guid>
      <pubDate>Wed, 18 Nov 2026 00:00:00 GMT</pubDate>
      <description><![CDATA[How the two Go programs behind the camt.053 and pain.001 pages work: request path, packages, types, and the Go idioms, read from Java.]]></description>
      <content:encoded><![CDATA[<p>This note is a reading of that code for someone new to go. I would recomend a visit of <a href="https://go.dev/tour/welcome/1">Tour of Go</a> which is highly recommended across the internet as an introduction.</p>
<p>As for what I have done here, the <a href="/software/">software page</a> there are two tools that are using go. They both read an ISO 20022 file in Go: a camt.053 bank statement, and a pain.001 credit transfer.</p>
<p>Both pages are themselves their own programs, they have their own set of source files that are combined in a package declaration that has its own entry point.</p>
<p>The examples are two programs, not two files. Each program is a <code>package main</code> with the same layout: a request handler, a parser, and tests. They read different ISO 20022 XML message types, but the roles of the Go files are alike.</p>
<h2>Where the code is</h2>
<p>Both function directories use the same file layout:</p>
<table>
<thead>
<tr>
<th>File</th>
<th>What it does</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>main.go</code></td>
<td>Starts the program and handles HTTP requests. It decodes the request body, calls the parser, and writes the HTTP response.</td>
</tr>
<tr>
<td><code>parse.go</code></td>
<td>Defines the XML and JSON data structures, decodes and validates the message, then maps it to the data the page displays.</td>
</tr>
<tr>
<td><code>parse_test.go</code></td>
<td>Tests the parser, including parsing the sample XML and rejecting invalid input.</td>
</tr>
<tr>
<td><code>go.mod</code></td>
<td>Declares the program's Go module path and dependencies.</td>
</tr>
<tr>
<td><code>go.sum</code></td>
<td>Records checksums for dependency versions.</td>
</tr>
</tbody>
</table>
<p>The <a href="/camt/">statement reader</a> uses these files under <code>netlify/functions/camt/</code>; its module is <code>hostlund.com/camt</code>. Its parser handles camt.053:</p>
<p>The <a href="/pain/">payment reader</a> has the same files under <code>netlify/functions/pain/</code>; its module is <code>hostlund.com/pain</code>.</p>
<h2>What each program does</h2>
<h3>CAMT</h3>
<p><code>parseCamt</code> in <code>netlify/functions/camt/parse.go</code> decodes a bank-to-customer statement. The document element it maps is <code>BkToCstmrStmt/Stmt</code>. For each statement it builds a <code>statementView</code>: an id, a creation time, the account (IBAN, or the other account id when there is no IBAN, plus currency and name), the balances, and the entries. Balance codes such as <code>OPBD</code> and <code>CLBD</code> become labels ("Opening booked", "Closing booked") in <code>balanceLabel</code>. Credit and debit indicators <code>CRDT</code> and <code>DBIT</code> become "Credit" and "Debit" in <code>direction</code>.</p>
<p>An entry can contain transaction details. <code>entryViews</code> flattens <code>NtryDtls/TxDtls</code>. When those details exist, the amount prefers the transaction amount, then the detail amount, then the entry amount. The counterparty depends on the direction: a debit's other party is the creditor, and a credit's other party is the debtor, falling back to the creditor when the debtor name is empty. That logic is <code>counterparty</code>. When an entry has no transaction details, the view still has the entry amount, dates, status, servicer reference, and additional info.</p>
<p>The group header of the sample statement (<code>GrpHdr</code>, message id <code>SAMPLE-2026-02</code>) is not mapped. <code>encoding/xml</code> skips elements that no struct field asks for.</p>
<h3>PAIN</h3>
<p><code>parsePain</code> in <code>netlify/functions/pain/parse.go</code> decodes a customer credit transfer initiation, <code>CstmrCdtTrfInitn</code>. The JSON is one <code>paymentView</code>: the group header (message id, created time, initiator, count, control sum) and a list of payment blocks. Each block has the debtor, the debtor IBAN (or the other account id), the debtor BIC (<code>BICFI</code>, or the older <code>BIC</code> tag when <code>BICFI</code> is empty), the execution date, and the transfers. A transfer's account is the creditor IBAN, or the other account id. Remittance is the unstructured <code>Ustrd</code> lines joined with spaces.</p>
<p>A few parsed fields are not copied onto the JSON. On a transfer, <code>InstrId</code> and the creditor BIC are unmarshaled and then left off <code>transferView</code>. The page does not show them.</p>
<p>Both parsers reject an empty body and a document that does not have the expected shape. camt returns "no statement was found in the file" when no <code>Stmt</code> was mapped. pain returns "no payment was found in the file" when the message id is empty and there are no payment blocks.</p>
<h2>How they are exposed</h2>
<p>The software page links to <code>/camt/</code> and <code>/pain/</code>, and describes the two readers in a sentence each.</p>
<p><code>src/pages/camt.js</code> posts the XML to <code>/api/camt</code> and renders <code>statements</code>: the account line, a balance table (<code>label</code>, <code>date</code>, <code>creditDebit</code>, <code>amount</code>, <code>currency</code>), and an entry table (<code>bookingDate</code>, <code>valueDate</code>, <code>creditDebit</code>, <code>amount</code>, <code>counterparty</code>, <code>endToEndId</code> or <code>reference</code>, <code>remittance</code>).</p>
<p><code>src/pages/pain.js</code> posts to <code>/api/pain</code> and renders the payment object itself: initiator, message id, count, control sum, and each block's debtor, IBAN, BIC, execution date, and transfers.</p>
<p>Both pages put the message in a text box. Load example fills that box with the sample. The page says the message is not stored. Nothing in the Go writes the body to disk or to a database. The response sets <code>cache-control: no-store</code>.</p>
<h2>How a request is handled</h2>
<p>The shape of <code>main.go</code> is the same in both programs.</p>
<p><code>handler</code> accepts only <code>POST</code>. Anything else is HTTP 405. <code>requestBody</code> base64-decodes the body when <code>IsBase64Encoded</code> is set, which is the API Gateway proxy behaviour, and otherwise uses the body as bytes. <code>evaluate</code> rejects a body over <code>maxBytes</code> (1000000) with HTTP 413, calls the parser, and on success returns 200. camt wraps the slice as <code>{"statements": ...}</code>. pain marshals the <code>paymentView</code> as the whole body. A parser error becomes HTTP 400 with <code>{"error": "..."}</code>.</p>
<p><code>main</code> has two modes. The statement program reads stdin when <code>CAMT_DEV</code> is <code>stdin</code>. The payment program does the same when <code>PAIN_DEV</code> is <code>stdin</code>. In that mode it prints the status code, a newline, and the JSON. Otherwise it calls <code>lambda.Start(handler)</code>.</p>
<p>In <code>gatsby develop</code>, <code>gatsby-node.js</code> mounts <code>POST /api/camt</code> and <code>POST /api/pain</code>. Each mount runs <code>go run .</code> in the function directory with that environment variable set to <code>stdin</code>, passes the request body as the process input, and splits stdout on the first newline into a status and a payload. The timeout is 60 seconds. If the process fails or prints no newline, the dev server responds 500 with <code>{"error":"The file could not be read."}</code>.</p>
<p>On the deployed site, Netlify routes requests to <code>/api/camt</code> or <code>/api/pain</code> to the corresponding Go function. The Go <code>main</code> function starts its handler; <code>main.go</code> itself is not a URL endpoint. The redirect rules in <code>netlify.toml</code> map <code>/api/camt</code> to <code>/.netlify/functions/camt</code> and <code>/api/pain</code> to <code>/.netlify/functions/pain</code>. Their <code>status = 200</code> makes these rewrites: the function handles the request while the browser continues using the <code>/api/...</code> URL. <code>force = true</code> applies each rule even if a file happens to exist at that path.</p>
<p>The <code>[build]</code> section in <code>netlify.toml</code> runs <code>npm install &#x26;&#x26; npm run build</code> and publishes <code>public</code> for the Gatsby site. That command does not compile the Go programs. Netlify separately discovers and builds functions from the conventional <code>netlify/functions</code> directory, where <code>camt</code> and <code>pain</code> each have their own <code>go.mod</code>. The <code>[build.environment]</code> section sets build-time values such as the Node.js version and <code>GATSBY_CPU_COUNT</code>; it does not set <code>CAMT_DEV</code> or <code>PAIN_DEV</code>. With those variables unset in deployment, each Go <code>main</code> takes the <code>lambda.Start(handler)</code> path. The remaining <code>[[headers]]</code> rules set cache and content-type headers for parking pages and their manifest; they do not configure the Go functions.</p>
<h2>Idioms, for a Java developer</h2>
<p><strong>One package, several files.</strong> Every file says <code>package main</code>. All of the functions and types in the directory are in one package, and <code>main</code> is the entry point, the same role as <code>public static void main</code>. There is no class wrapping them. Java would have made <code>parseCamt</code> a method on a class. Go lets the function sit at package scope.</p>
<p><strong>Visibility is the capital letter.</strong> <code>parseCamt</code>, <code>handler</code>, and <code>statement</code> start with a lowercase letter, so another module cannot call them. The tests are <code>package main</code>, not <code>package main_test</code>, so they can call <code>parseCamt</code> directly. A Java test in the same package can call a package-private method for the same reason. The module path in <code>go.mod</code> is the import path, closest to Maven coordinates.</p>
<p><strong>Errors are values.</strong> <code>parseCamt</code> returns <code>([]statementView, error)</code>. The caller writes <code>if err != nil</code>. There is no <code>throw</code> and no checked exception. <code>fmt.Errorf</code> builds the error. HTTP status is not the Go <code>error</code> return. <code>handler</code> almost always returns a nil error and puts 400, 405, or 413 on the response. The <code>error</code> return is the function runtime's failure channel. A nil error with a 400 response means "the invocation succeeded, the file did not."</p>
<p><strong>Structs instead of beans.</strong> A struct is a block of fields. Go does not provide a default constructor or require a constructor call: declaring a variable gives it the type's zero value, and <code>paymentView{}</code> explicitly creates that zero-valued struct. On failure, pain returns <code>paymentView{}</code>, whose fields are <code>""</code>, <code>nil</code>, or <code>0</code>. These files define no constructor functions. <code>toView</code> fills a struct with a composite literal, which resembles a constructor call with named fields. The <code>.go</code> files in each directory are compiled together as one package; when the program starts, Go initializes package-level variables and then calls <code>main</code>. The structs are created as the code runs, for example while parsing a request—not loaded from the source files as pre-made objects.</p>
<p><strong>Slices instead of ArrayList.</strong> <code>views := make([]statementView, 0, len(doc.Statements))</code> allocates a slice with length 0 and enough capacity for the statements, then <code>append</code> adds to it. The capacity argument is the same idea as <code>new ArrayList&#x3C;>(n)</code>. <code>append</code> may allocate a larger array if the capacity is exceeded. <code>flatten</code> starts from a nil slice and appends. A nil slice marshals as JSON <code>null</code> if it is ever returned directly. The views in this code are built with <code>make</code>, so an empty list of balances or transfers marshals as <code>[]</code>.</p>
<p><strong>The interface is implicit.</strong> <code>localNames</code> does not declare that it implements a type. <code>xml.NewTokenDecoder</code> asks for a <code>TokenReader</code>, which is an interface with one method, <code>Token() (Token, error)</code>. Having the method is enough. Java would say <code>implements TokenReader</code>. The method has a value receiver, <code>func (l localNames) Token()</code>, and the decoder pointer lives inside the struct, so the copy still reads the same underlying decoder. The loop <code>for i := range element.Attr</code> uses the index because a <code>range</code> value is a copy. Writing through the index updates the attribute that is returned. That is a common Go slip, and this code avoids it.</p>
<p><strong><code>switch</code> does not fall through.</strong> <code>direction</code> and <code>balanceLabel</code> switch on the upper-cased code and return from each case. There is no <code>break</code>. A case ends at the next case.</p>
<p><strong>Variadic helpers.</strong> <code>firstText(values ...string)</code> is <code>String...</code> in Java. It returns the first value that is not blank after <code>strings.TrimSpace</code>. Dates use it so a date-only tag wins when it is present and a date-time tag is the fallback: <code>firstText(item.BookingDate, item.BookingTime)</code>.</p>
<p><strong><code>any</code>.</strong> <code>map[string]any{"statements": statements}</code> is a map from string to an arbitrary value, closest to <code>Map&#x3C;String, Object></code>. <code>any</code> is a predeclared alias for <code>interface{}</code>. This code does not use type parameters beyond that.</p>
<p><strong>Short declarations.</strong> <code>stmt := statements[0]</code> declares and assigns. The type comes from the right-hand side, the same information <code>var</code> carries in Java, written at the call.</p>
<p><strong>Tests.</strong> <code>parse_test.go</code> imports the <code>testing</code> package. <code>t.Fatal</code> fails the test and stops it, in the role of an assertion failure. There is no test class and no framework in these files. <code>go test</code> finds the files by the <code>_test.go</code> suffix.</p>
<h2>What this code does not use</h2>
<p>There are no goroutines, no channels, and no mutexes. Concurrency is not a reason this program is in Go. The reasons visible in the code are the small runtime, the XML and JSON libraries, a single binary, and the function entry point.</p>
<p>There is no shared internal package. The duplication of <code>localNames</code>, <code>amount</code>, <code>firstText</code>, and <code>cleanList</code> is the cost of that.</p>]]></content:encoded>
    </item>
    <item>
      <title>A free-parking map for Berlin</title>
      <link>https://www.hostlund.com/learning/berlin-parking/</link>
      <guid isPermaLink="true">https://www.hostlund.com/learning/berlin-parking/</guid>
      <pubDate>Sun, 15 Nov 2026 00:00:00 GMT</pubDate>
      <description><![CDATA[How the parking page uses the city's open zone data, a point-in-polygon check, and a small parser for messy opening hours.]]></description>
      <content:encoded><![CDATA[<p>The <a href="/parking/">parking page</a> answers a practical question: is this place in a Berlin parking zone, and do parking charges apply right now?</p>
<h2>Open data</h2>
<p>The zones come from the Berlin Geoportal, the layer Parkraumbewirtschaftung. The service is a WFS. A GeoJSON snapshot of the 104 zone polygons is stored in the repo, and <code>scripts/parkzonen/refresh.mjs</code> downloads a fresh copy. The script trims the fields and turns the free-text hours into day and hour ranges where the text matches a pattern the tests know.</p>
<p>The licence is Datenlizenz Deutschland – Zero – Version 2.0. It sets no conditions and does not require attribution. The page credits Geoportal Berlin / Parkraumbewirtschaftung anyway.</p>
<h2>Inside a zone, and outside all of them</h2>
<p>A point-in-polygon test says whether the address sits in a zone. The pin on the map is then moved to the nearest drivable street, because a search hit can land on a building. The suggested parking place is not that boundary. It is the nearest kerb, from the city's street-parking map, that is outside every paid zone and is not a no-stopping restriction. The kerb has to sit on a drivable street, and not in a park, on water, on railway land, or in a station. Neighbouring zones share edges, so a point just outside one polygon is often still inside the next one, or in a park such as Mauerpark. Turf does the point-in-polygon tests.</p>
<p>The distance on the page is straight across the map. The walking time takes that distance, multiplies by 1.3, and assumes 5 km/h. It is labelled as an estimate. It is not a walking route.</p>
<h2>Messy hours</h2>
<p>The hour field is written by hand. Most lines look like "Mo-Sa 9-22 Uhr". Some repeat the same text twice, some put a slash between the weekday hours and Saturday, and one mentions Advent Saturdays. The parser accepts the shapes that appear in the file. The Advent line does not parse. The raw text is kept, and the page says to check the signs for charging hours.</p>
<p>Whether charges apply is decided in the browser from those ranges and the clock in Europe/Berlin. The end of a range is exclusive, so charges stop at 22:00 when the text says 9-22. A Bewohnerparkausweis is a separate rule: with one, you can park in your own zone. The page says so. It does not know who has one.</p>
<h2>The rest of the map</h2>
<p>The base map is OpenStreetMap, drawn with MapLibre and OpenFreeMap tiles. Search uses Photon, biased to Berlin. A public-transport duration, when the request succeeds, comes from the VBB community API. There is no API key. If that request fails, the zone answer and a link to transit directions still show.</p>
<p>Signs on the street are the rule that counts. A zone polygon can be out of date, and a single block can differ from the zone around it. The page says that, and it does not claim otherwise.</p>]]></content:encoded>
    </item>
  </channel>
</rss>
