Getting started
Install go-bananas and stand up a minimal SSR server.
Install
go-bananas requires Go 1.26 or newer.
go get github.com/mikehelmick/go-bananas@latest
A minimal server
The snippet below renders an HTML page through the render
package and serves it with the graceful server. Templates are loaded
from any fs.FS — an embed.FS in production.
package main
import (
"context"
"embed"
"net/http"
"github.com/gorilla/mux"
"github.com/mikehelmick/go-bananas/middleware"
"github.com/mikehelmick/go-bananas/render"
"github.com/mikehelmick/go-bananas/server"
"github.com/mikehelmick/go-bananas/webctx"
)
//go:embed templates static
var assets embed.FS
func main() {
ctx := context.Background()
h, err := render.New(assets, render.WithDevMode(true))
if err != nil {
panic(err)
}
r := mux.NewRouter()
r.Use(middleware.Recovery(h))
r.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
m := webctx.TemplateMapFromContext(req.Context())
m.Title("Home")
h.RenderHTML(w, "home", m)
})
// Serve the embedded static assets the renderer's SRI tags point at.
static := middleware.ConfigureStaticAssets(true)
r.PathPrefix("/static/").Handler(static(http.FileServerFS(assets)))
srv, err := server.New("8080")
if err != nil {
panic(err)
}
_ = srv.ServeHTTPHandler(ctx, r)
}
With a templates/home.html containing:
{{ define "home" }}<!doctype html>
<title>{{ .title }}</title>
<h1>Hello, Bananas 🍌</h1>{{ end }}
Next steps
- The middleware chain — assemble recovery, logging, secure headers, sessions, and CSRF in the right order.
- Rendering & templates — the FuncMap, SRI asset tags, and hot reload.
- Forms — bind, validate, and re-render an HTML form with preserved input and inline errors.
- Configuration — compose per-package env-tagged
Configstructs with go-envconfig. - The runnable
examples/ssr-oidcapplication ties everything together, including OIDC.