Rewrite API in Go #87
Loading…
Reference in a new issue
No description provided.
Delete branch "doridian/golang-rewrite"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Rewrites the Elixir/Phoenix API in Go. The goal is a drop-in replacement: same routes, same JSON shapes, same auth, same database.
Layout / build
Follows the current SpaceAge/TTS and FoxDen Go conventions:
cmd/space_age_api,util/info.go(gitrev via ldflags),internal/api,internal/dbbuildGoModulewithvendor-hash.txt(+.docfor auto-nix-hash), maidtasks/gorenovate presetmanaged-go.ymlreplaceselixir-lint.yml(golangci-lint, build, test)bin/space_age_api, so the existing NixOS module keeps working unchanged.startruns the server;stop/restartare accepted as no-ops for the currentExecStop/ExecReload. It reads the same env vars:SECRET_KEY_BASE,PORT,MYSQL_SOCKET,MYSQL_USERNAME,MYSQL_PASSWORD,MYSQL_DATABASE,POOL_SIZE.Compatibility
schema_migrationstable, so on the existing DBspace_age_api migrateis a no-op. On a fresh MariaDB,SHOW CREATE TABLEof every table is byte-identical to what Ecto produces. Migrations don't run onstartunlessAUTO_MIGRATEis set, same as the old release.SECRET_KEY_BASE,iss=Joken, sameaudvalues and lifetimes. Tokens issued by the old API are accepted by the new one and the reverse, so a deploy doesn't log anyone out. Unit tests use real Joken-signed fixture tokens."1"/"true"count as booleans, and errors come back as{"errors": {"field": ["is invalid" | "can't be blank"]}}.{}404s, the ErrorView bodies,Cache-Controlper route,Client-Identity, CORS headers and preflight, text responses without a Content-Type, and thesteam://redirect.Intentional differences
All of these were 500s (crashes) in the old API:
POST /v2/rabbitmq/userqueriedservers.authkey, which doesn't exist (Ecto.QueryErroron every call). It now checksserver_configsname + authkey, which is what the STOMP central login (server name + serverToken) needs.servers.playerscrashed while formatting the error (to_stringon the{:array, :string}type). It now returns a normal 400.Authorizationheader with no token, or Discord requests with missing or non-hex signature headers, now get 401 instead of a 500.[]is accepted for map fields (research,station_storage) and an empty{}forplayers. Previously these rejected the whole save./salinkfor a Discord account already linked to another SteamID now moves the link. Before, it hit the unique index and 500'd.PUT /v2/servers/selfignores anamein the body and always uses the authenticated server. The client never sends one.create_serversusesENGINE = INNODBinstead ofMEMORY. The original migration can't run on MariaDB or MySQL at all (MEMORY doesn't support JSON/TEXT columns; checked with the old release too). This only affects fresh installs, since existing DBs already have the version recorded.Testing
main) and the new binary ran side by side against identical MariaDB 11.8 databases, and a script replayed ~110 requests shaped like the Lua client's (players, JWTs in both directions, applications, bans, servers, factions, RabbitMQ, Discord rejection paths, CORS, and error cases). Result: 0 unexpected differences; the only differences are the ones listed above. Final DB contents matched except the one row from the intentionalplayers: {}leniency./salinklink, move, unlink and invalid-code flows were tested end to end against the Go build with a test key.go test ./...,golangci-lint(0 issues),nix build,nixfmt-tree --ci.Deploying
Nothing is required. As an optional follow-up in
FoxDen/core,spaceage/api.nixcan dropExecStop/ExecReloadand addExecStartPre = "... migrate"if you want migrations applied automatically.🤖 Generated with Claude Code