Pisigo is a lightweight, production-oriented HTTP framework for Go.
Module: github.com/arnaudovproject/pisigo
Pisigo gives you a small core (router, context, middleware, errors) and optional adapters for SQL, MongoDB, Redis, NATS, metrics, tracing, auth, sessions, and more — without forcing a heavy application architecture.
- Familiar handler style with explicit errors
- First-class middleware and route groups
- Built-in request binding and validation
- Graceful shutdown, TLS, trusted proxies
- Pluggable store / queue / pubsub interfaces
- CLI for scaffolding, local development, migrations, and AI agent rules
- Go 1.26.1+
go get github.com/arnaudovproject/pisigo@latestgo install github.com/arnaudovproject/pisigo/cmd/pisigo@latestpackage main
import (
"log"
"github.com/arnaudovproject/pisigo"
"github.com/arnaudovproject/pisigo/middleware"
)
func main() {
app := pisigo.Boot()
app.Use(
middleware.Recover(),
middleware.RequestID(),
middleware.Logger(),
middleware.Secure(),
)
app.GET("/", func(c *pisigo.Context) error {
return c.JSON(200, map[string]string{"status": "ok"})
})
if err := app.Server("0.0.0.0", 8080); err != nil {
log.Fatal(err)
}
}pisigo new myapp
cd myapp
# wire the module replace / go get as needed
pisigo install agents all # optional: Cursor / Claude / Codex project rules
pisigo dev .Pisigo can install project-local instructions for popular coding agents so they understand the framework (routing, handlers, middleware, auth, adapters, recommended layout) with less prompting and fewer tokens.
Run from your application root (the project that already depends on Pisigo):
pisigo install agents all
pisigo install agents cursor
pisigo install agents claude
pisigo install agents codex
pisigo install agents cursor claude --force
pisigo install agents all -d ./myapp| Target | What gets created | Used by |
|---|---|---|
cursor |
.cursor/rules/pisigo-*.mdc |
Cursor project rules |
claude |
CLAUDE.md + .claude/rules/pisigo-*.md |
Claude Code |
codex |
AGENTS.md |
OpenAI Codex / AGENTS.md-compatible tools |
all |
Everything above | — |
Flags:
-d, --dir <path>— project root (default.)-f, --force— overwrite existing files (default skips existing)
Dense, English guidance covering:
- How Pisigo boots, routes, groups, and handles errors
- Recommended
cmd/+internal/{http,service,repository,domain}layout - Middleware, auth, sessions, binding/validation patterns
- SQL / Mongo / store / queue / pubsub adapter usage
- Migrations, health, metrics, and CLI commands
Commit the generated files in your application repo so the whole team gets the same agent context. Re-run with --force after upgrading Pisigo if templates improve.
app := pisigo.Boot()
app.GET("/users/{id}", handler).SetName("user.show")
app.POST("/users", createUser)
api := app.Group("/api", authMiddleware)
api.GET("/me", me)
path, _ := app.Reverse("user.show", "id", "42") // /users/42Supported methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, CONNECT, TRACE, plus ANY.
*pisigo.Context wraps request/response helpers:
| Area | Helpers |
|---|---|
| Request | Param, Query, Bind, BindJSON, FormValue, BearerToken, Body |
| Response | JSON, HTML, XML, String, Data, File, Download, Redirect, NoContent |
| Store | Set, Get, MustGet |
| Misc | IP, IsHTTPS, Log, Cookie, Header |
Pooling: Context values are reused from a sync.Pool. Do not retain or access a *pisigo.Context after the handler returns (including from another goroutine) unless you call DetachFromPool() and later Release().
Return *pisigo.HTTPError (or sentinels like pisigo.ErrNotFound). The default error handler renders JSON:
return pisigo.NewHTTPError(400, "invalid input").WithDetails(map[string]any{
"field": "email",
})c.Bind(&in) unmarshals JSON/XML and validates validate struct tags via go-playground/validator.
| Middleware | Purpose |
|---|---|
Recover |
Panic recovery (stack stays in logs, client gets generic 500) |
Logger |
Structured request logging (no bodies/secrets by default) |
RequestID |
X-Request-ID propagation (validated; max 128 chars [A-Za-z0-9_-]) |
CORS |
Cross-origin headers (credentials-safe) |
Timeout |
Request timeout — returns 504 without blocking on slow handlers; cannot replace an already-committed response; handlers must respect c.Request().Context() |
Secure |
Security headers; HSTS only for TLS or trusted-proxy HTTPS |
BasicAuth |
HTTP Basic |
RateLimit |
Token / window limiting |
Compress |
Gzip responses |
CSRF |
CSRF cookie + header/form check |
Cache |
Response cache via store.Store |
app.Use(
middleware.Recover(),
middleware.RequestID(),
middleware.Logger(),
middleware.CORS(),
middleware.Timeout(15*time.Second),
)cfg := auth.DefaultJWTConfig("your-secret")
token, _ := auth.Issue(cfg, "user-id", []string{"admin"}, nil)
app.Use(auth.JWT(cfg), auth.RequireRoles("admin"))
app.Use(auth.APIKey("X-API-Key", func(k string) bool { return k == "secret" }))
app.Use(session.Middleware(session.Config{
Store: session.NewMemoryStore(),
// Secure cookies are on by default. For local HTTP:
// InsecureCookie: true,
}))Use these defaults and settings for internet-facing services:
- CORS — allowlist exact origins; never combine
AllowOrigins: ["*"]withAllowCredentials: true(Pisigo ignores the wildcard in that case). - Trusted proxies — call
app.SetTrustedProxies(...)only for your load balancer / reverse proxy CIDRs. Client IP andIsHTTPS()/ HSTS honor forwarded headers only from trusted peers. - Cookies — session and CSRF cookies are
Secureby default; useInsecureCookie: true/CSRF(CSRFConfig{Secure: false})only on plain HTTP. - WebSocket — default
CheckOriginis same-origin; pass a custom allowlist viawebsocket.Configif needed. - Postgres — DSN default
sslmode=require; setSSLMode: "disable"only for local databases. - Body size — default max body is 1 MiB (
SetMaxBodyBytes); form/multipart parsing respects the same limit. - Metrics — protect the endpoint:
m.Register(app, "/metrics", middleware.BasicAuth(...)). - Realtime (SSE/WS) — use
pisigo.StreamingServerConfig()(WriteTimeout disabled) or set timeouts explicitly viaServerWithConfig. - Rate limit — store errors fail closed (503); prefer Redis rate limit store in multi-instance deployments.
- Timeout — handlers must respect
c.Request().Context(); Timeout returns 504 promptly and does not wait for ignored cancellation. If the handler already wrote headers/body, Timeout cannot replace that response with 504 (HTTP responses are not rewindable). - Server errors —
Server/ServerWithConfigreturnerror(e.g. bind failure); always check it.
if err := app.ServerWithConfig("0.0.0.0", 8080, pisigo.StreamingServerConfig()); err != nil {
log.Fatal(err)
}import "github.com/arnaudovproject/pisigo/adapters/sqlite"
sqlDB, err := sqlite.OpenMemory()
// postgres, mysql, mssql adapters availabledb.SQL provides Get, Select, Exec, Query, Transaction, pool options, and DSN builders.
import "github.com/arnaudovproject/pisigo/adapters/mongodb"
mdb, err := mongodb.Open(mongodb.Config{
URI: "mongodb://localhost:27017",
Database: "app",
})Interfaces live in store, queue, and pubsub.
| Backend | Store | Queue | PubSub | Rate limit |
|---|---|---|---|---|
| Memory | yes | yes | yes | via middleware |
| Redis | yes | yes | — | yes |
| NATS | — | JetStream | yes | — |
pisigo migrate create add_usersm := migrate.New(sqlDB, "migrations")
_ = m.Up(ctx)
_ = m.Down(ctx, 1)SQL files use:
-- +migrate Up
CREATE TABLE users (...);
-- +migrate Down
DROP TABLE users;h := health.New()
h.Ready("db", func(ctx context.Context) error { return sqlDB.Ping(ctx) })
h.Register(app, "/health") // /health/live, /health/readym := metrics.New("myapp")
app.Use(m.Middleware())
m.Register(app, "/metrics", middleware.BasicAuth(middleware.BasicAuthConfig{
Validator: func(u, p string) bool { return u == "prom" && p == "secret" },
}))shutdown, _ := otelx.Setup("myapp")
defer shutdown(context.Background())
app.Use(otelx.Middleware("myapp"))Setup configures W3C TraceContext propagation. Swap the stdout exporter for OTLP in your app when shipping to a collector.
openapi.Register(app, "/openapi.json", "My API", "1.0.0")
// also serves /docs (Swagger UI)- WebSocket —
websocket.Upgrade/websocket.Handler - SSE —
sse.Open+Event/Comment/Retry
| Command | Description |
|---|---|
pisigo new <name> |
Scaffold a new app |
pisigo dev [path] |
Run with auto-reload |
pisigo prod [path] [-o out] |
Production build |
pisigo generate handler <name> |
Handler stub |
pisigo migrate create <name> |
Migration file |
pisigo install agents <target> |
Install AI agent rules (cursor, claude, codex, or all) |
pisigo install agents all
pisigo install agents cursor claude --forceSee AI agent rules for formats and details.
Use the built-in helpers:
import pisigotest "github.com/arnaudovproject/pisigo/testing"
res := pisigotest.GET(app, "/hello")
res = pisigotest.POST(app, "/in", map[string]string{"email": "a@b.com"})Run the suite:
go test ./...CI runs the same suite on every push and pull request.
pisigo/
├── app.go, router.go, context.go, server.go # HTTP core
├── middleware/ # HTTP middleware
├── auth/, session/, config/, i18n/ # Cross-cutting
├── db/, migrate/, adapters/ # Data adapters
├── store/, queue/, pubsub/ # Messaging interfaces
├── health/, metrics/, otelx/, openapi/ # Observability / docs
├── websocket/, sse/, circuit/ # Realtime & resilience
├── testing/ # Test helpers
└── cmd/pisigo/ # CLI (+ embedded agent templates)
cfg, _ := config.LoadEnvFile(".env")
port := cfg.Int("PORT", 8080)
debug := cfg.Bool("DEBUG", false)
timeout := cfg.Duration("TIMEOUT", 15*time.Second)Also supports LoadJSONFile (nested keys flattened as db.host) and LoadEnv.
MIT — see LICENSE.