Fork me on GitHub
Digital Commons

go-ruby-sinatra

Ruby's Sinatra routing & dispatch core in Go — MRI-faithful, .

MRI-faithfulroute tableMustermann patterns:name · * · :name?before/after filtershalt · pass · redirectRack tupleon go-ruby-rack100% coverage6 arches
Documentation (MkDocs Material + mike) Go 1.26.4+ Coverage 100%
zsh
$ go get github.com/go-ruby-sinatra/sinatra@latest

go-ruby-sinatra is a pure-Go (no cgo) reimplementation of the deterministic core of Ruby's Sinatra — a per-verb route table, a Mustermann-style pattern compiler (:name, *, :name?, raw regexp), the params merge (query + form seeded, route captures override via v2 || v1), and the dispatcher (before/after filters, halt/pass/redirect, not_found/error) that assembles the Rack [status, headers, body] tuple — matching the reference sinatra gem (4.x) without any Ruby runtime. It is built on go-ruby-rack, reusing rack.Request/rack.Response, and is the Sinatra backend for go-embedded-ruby, bound by rbgo as a native module just like go-ruby-regexp, go-ruby-erb and go-ruby-json — differential-tested against the MRI sinatra gem, 100% coverage, CI green across 6 arches and 3 OSes.

Routing table ready

A per-verb route table — Get/Post/Put/Delete/Patch/Options/Head plus Route for arbitrary verbs — with first-match-wins ordering. Get also registers HEAD, exactly like Sinatra.

Pattern compiler ready

Mustermann-style "/hello/:name" named captures, * splats, the optional trailing ?, and raw regexp routes, compiled to an anchored regexp with Sinatra’s exact :name → [^/?#]+, :name? → (…)?, * → .*? semantics; captures are URI-decoded.

Params merge ready

Request query + form params seed params, then route captures override on collision via Sinatra’s v2 || v1 rule; splats accumulate into params["splat"] and regexp groups into params["captures"].

Dispatch & filters ready

before/after filters with their own patterns and capture merge, halt/pass/redirect/status/content_type/headers/body, and the not_found/error(code) handlers, producing the Rack [status, headers, body] tuple.

Helpers & settings ready

content_type mime resolution with Sinatra’s add_charset rule, url/uri resolution, conditional halt, and a set/enable/disable settings registry — all built on rack.Request/rack.Response.

Differential oracle & coverage ready

The same routes compiled under the real sinatra gem (4.x) and compared byte-for-byte — route→params, filter order, halt/pass/redirect, content_type and the Rack tuple; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.

Templating & session planned

ERB/Haml rendering, the session store and the Ruby do…end action bodies are documented seams the embedding runtime (rbgo) supplies; the HTTP server (socket accept, TLS, Rack::Handler) is the host’s job and out of scope.

A faithful port of Sinatra's routing and dispatch core in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. It compiles Mustermann-style route patterns, extracts params (named captures, splats, the query merge), orders before/after filters and the halt/pass control flow, and assembles the Rack [status, headers, body] tuple. Validated differentially against the reference sinatra gem. The action bodies, session store and template rendering are documented seams the embedding runtime supplies; it is the Sinatra backend for the sibling org github.com/go-embedded-ruby.