gobananas

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

🍌 go-bananas

The application framework for Go that is so simple, it's Bananas.

CI Go Reference Go Report Card License

go-bananas is a lean, server-side-rendered (SSR) web framework plus a small application-infrastructure layer for Go. It is assembled from focused, composable packages — a template renderer, composable middleware, CSRF, secure-cookie sessions, flash messages, form binding/validation, a graceful HTTP server, and pluggable secrets/keys — so you import only what you need. A single pluggable Authenticator seam makes OIDC a wiring exercise, not a framework dependency, and configuration is plain env vars via go-envconfig.

It is extracted and generalized from Google's exposure-notifications-verification-server and exposure-notifications-server.

📚 Documentation

Install

go-bananas requires Go 1.26 or newer.

go get github.com/mikehelmick/go-bananas@latest

Quick start

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)
}

See the getting-started guide for the full picture, including the recommended middleware chain.

Packages

Web layer

Package Purpose
render html/text template renderer with a rich FuncMap and SRI asset tags
middleware Composable gorilla/mux middleware + the Authenticator seam
form SSR form binding + validation (form/validate tags) for the parse → validate → re-render loop
session · flash · cookiestore Typed session accessors, one-shot flash messages, hot-reloadable cookie store
webctx · response Request-scoped context helpers and HTTP response/error helpers
i18n gettext (.po) translations with Accept-Language matching

Infrastructure layer

Package Purpose
server Gracefully-stoppable HTTP server
secrets · keys Pluggable secret/key managers (filesystem + in-memory core; cloud opt-in)
cache Generic, TTL-based in-memory cache
logging Context-scoped log/slog logger + logging.Config (LOG_LEVEL/LOG_MODE)
Opt-in cloud providers

The core secrets and keys packages have no cloud dependencies. Cloud providers are self-registering sub-packages you blank-import, so their SDKs are only linked when used:

import _ "github.com/mikehelmick/go-bananas/secrets/gcp"   // or aws, azure, vault
import _ "github.com/mikehelmick/go-bananas/keys/gcp"      // or aws, azure, vault
Configuration

There is no config package. Packages that need settings expose an env-tagged Config struct (logging.Config, secrets.Config, keys.Config); an app composes them into its own config and processes everything once with go-envconfig:

type appConfig struct {
	Logging logging.Config // LOG_LEVEL, LOG_MODE
	Secrets secrets.Config

	DevMode bool   `env:"DEV_MODE, default=false"`
	Port    string `env:"PORT, default=8080"`
}

var cfg appConfig
if err := envconfig.Process(ctx, &cfg); err != nil { /* handle */ }
logger := logging.NewLoggerFromConfig(cfg.Logging)

Claude Code skills

This repo ships Claude Code skills that help developers and agents build go-bananas apps (scaffolding, the middleware chain, authentication, and secrets/keys). Install them via the plugin marketplace:

/plugin marketplace add mikehelmick/go-bananas

Contributing

Issues and pull requests are welcome. Run make test and make lint before submitting.

License

Apache 2.0 — see LICENSE. Significant portions are extracted from the Exposure Notifications projects (Google LLC), also Apache 2.0.

Documentation

Overview

Package gobananas is the documentation root for go-bananas, the application framework for Go that is so simple, it's Bananas.

go-bananas is a lean, server-side-rendered (SSR) web framework plus a small application-infrastructure layer. It is assembled from focused, composable packages rather than a single monolith, so you import only what you need.

Web layer

Infrastructure layer

See the example application under examples/ssr-oidc for an end-to-end SSR app wiring these packages together, including an OIDC Authenticator.

Directories

Path Synopsis
Package cache implements a generic, in-memory, TTL-based cache for any object.
Package cache implements a generic, in-memory, TTL-based cache for any object.
Package cookiestore provides a github.com/gorilla/sessions.Store backed by encrypted cookies whose HMAC and encryption keys can be hot-reloaded.
Package cookiestore provides a github.com/gorilla/sessions.Store backed by encrypted cookies whose HMAC and encryption keys can be hot-reloaded.
Package flash implements one-shot "flash" messages: alerts, errors, and warnings that are stored on a session, surfaced once on the next render, and then automatically cleared on read.
Package flash implements one-shot "flash" messages: alerts, errors, and warnings that are stored on a session, surfaced once on the next render, and then automatically cleared on read.
Package form binds and validates HTML form submissions into Go structs.
Package form binds and validates HTML form submissions into Go structs.
Package i18n loads gettext (.po) translations from a filesystem and resolves the best locale for a request, implementing the github.com/mikehelmick/go-bananas/middleware.LocaleProvider seam so ProcessLocale — and the renderer's "t"/"tDefault" template functions — work out of the box.
Package i18n loads gettext (.po) translations from a filesystem and resolves the best locale for a request, implementing the github.com/mikehelmick/go-bananas/middleware.LocaleProvider seam so ProcessLocale — and the renderer's "t"/"tDefault" template functions — work out of the box.
internal
azureauth
Package azureauth provides the shared Key Vault authorizer used by the Azure secrets and keys providers.
Package azureauth provides the shared Key Vault authorizer used by the Azure secrets and keys providers.
util
Package util holds small, dependency-free helpers shared across go-bananas.
Package util holds small, dependency-free helpers shared across go-bananas.
Package keys defines a pluggable abstraction over key-management systems for signing and encryption.
Package keys defines a pluggable abstraction over key-management systems for signing and encryption.
aws
Package aws provides an AWS KMS backed github.com/mikehelmick/go-bananas/keys.KeyManager.
Package aws provides an AWS KMS backed github.com/mikehelmick/go-bananas/keys.KeyManager.
azure
Package azure provides an Azure Key Vault backed github.com/mikehelmick/go-bananas/keys.KeyManager.
Package azure provides an Azure Key Vault backed github.com/mikehelmick/go-bananas/keys.KeyManager.
gcp
Package gcp provides a Google Cloud KMS backed github.com/mikehelmick/go-bananas/keys.KeyManager.
Package gcp provides a Google Cloud KMS backed github.com/mikehelmick/go-bananas/keys.KeyManager.
vault
Package vault provides a HashiCorp Vault (transit engine) backed github.com/mikehelmick/go-bananas/keys.KeyManager.
Package vault provides a HashiCorp Vault (transit engine) backed github.com/mikehelmick/go-bananas/keys.KeyManager.
Package logging provides a context-scoped logger built on the standard library's log/slog.
Package logging provides a context-scoped logger built on the standard library's log/slog.
Package middleware provides composable github.com/gorilla/mux middleware for building server-side-rendered web applications.
Package middleware provides composable github.com/gorilla/mux middleware for building server-side-rendered web applications.
Package render renders HTML, JSON, and CSV responses from templates loaded out of an io/fs.FS.
Package render renders HTML, JSON, and CSV responses from templates loaded out of an io/fs.FS.
Package response provides HTTP response and error helpers that negotiate between HTML and JSON based on the request's Accept and Content-Type headers.
Package response provides HTTP response and error helpers that negotiate between HTML and JSON based on the request's Accept and Content-Type headers.
Package secrets defines a pluggable abstraction over secret managers.
Package secrets defines a pluggable abstraction over secret managers.
aws
Package aws provides an AWS Secrets Manager backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
Package aws provides an AWS Secrets Manager backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
azure
Package azure provides an Azure Key Vault backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
Package azure provides an Azure Key Vault backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
gcp
Package gcp provides a Google Secret Manager backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
Package gcp provides a Google Secret Manager backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
vault
Package vault provides a HashiCorp Vault backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
Package vault provides a HashiCorp Vault backed github.com/mikehelmick/go-bananas/secrets.SecretManager.
Package server provides a small, gracefully-stoppable HTTP server.
Package server provides a small, gracefully-stoppable HTTP server.
Package session provides typed, nil-safe accessors for the values the framework stores on a github.com/gorilla/sessions.Session, plus a helper to obtain the session's github.com/mikehelmick/go-bananas/flash.Flash.
Package session provides typed, nil-safe accessors for the values the framework stores on a github.com/gorilla/sessions.Session, plus a helper to obtain the session's github.com/mikehelmick/go-bananas/flash.Flash.
Package webctx provides typed helpers for storing and retrieving request-scoped values on a context.Context.
Package webctx provides typed helpers for storing and retrieving request-scoped values on a context.Context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL