This week, I finished the first big part of the C++ to Go migration: the step that turns a paid WooCommerce order from the competition website into a competition entry in CouchDB. Every registration passes through this step before its slip and email can be sent, so the Go version must behave exactly like the C++ one.

Getting Ready

At the start of the week, I committed last week’s fixes, so the Go service can run without risking real data. My supervisor, Dr. Shawn, also gave me access to a test copy of the competition website, so I could look at real order data safely, without changing anything.

Building the Step Piece by Piece

I ported the step one function at a time, and wrote unit tests for each one before moving on. The first was getPUID, which builds each entry’s ID from the product’s SKU, the order and line item numbers, and the order date. The new version must give every entry the same ID as the old system, so its test checks the result against a real ID made by the C++ code. This gave me a clear way to prove that both versions behave the same. The next was buildModel, which collects the form answers a participant fills in when registering, so they can appear on the slip and in the email.

Then I added makeOrderOne, the main step, which saves a new entry from one line item of a paid order and sets who receives the confirmation email. I also added changeForm for the change form. When a participant updates their registration, it finds their old entry and keeps the answers they didn’t change, and the new entry replaces the old one.

The last piece was the JWT (JSON Web Token), a digitally signed code that is printed as the QR code on each slip and proves the entry came from our system. loadKey reads the secret signing key from the database, and entryJWT signs a fresh token for every entry with ES256, using the golang-jwt library. Signing keys were new to me, so this part took the longest to understand. Finally, I added doOrderCompleted and connected it to pollChanges, the loop that watches CouchDB’s changes feed. Now, when an order is marked as completed, the Go service turns every item in it into an entry.

Testing with a Fake Database

Each test runs against an in-memory CouchDB from the kivik library, so it never touches real data. Some tests feed in broken orders on purpose, to check that the code stops with a clear error. One test failed at first because the test key I copied had turned into dots, so I changed the test to generate its own key. By Saturday, all 16 tests passed.

Next Week’s Plan

Next week, I will port the confirmation email to Go, so participants keep receiving their slip PDFs as before. I will also port the order note the service writes back to WooCommerce to record whether the email was sent. Then I will open my first pull request for Dr. Shawn to review, and move on to the CSV exports.

Categories: Experiential

0 Comments

Leave a Reply

Avatar placeholder

This site uses Akismet to reduce spam. Learn how your comment data is processed.