Help us shape the future of Go! Take the 2026 Go Developer Survey

secure

command
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Example: secure-by-default lagodev HTTP service.

Run with `go run ./examples/secure` and try the endpoints:

# 1. Health — passes through the security stack
curl -i http://localhost:8080/ping

# 2. Validation failure → 422 with {"errors":{...}}
curl -i -X POST http://localhost:8080/users \
     -H 'Content-Type: application/json' \
     -d '{"email":"not-an-email","name":""}'

# 3. Unknown field is rejected → 400
curl -i -X POST http://localhost:8080/users \
     -H 'Content-Type: application/json' \
     -d '{"name":"A","email":"a@b.co","ghost":1}'

# 4. Rate limit (3 req/10s) → 429 on the 4th
for i in 1 2 3 4; do curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8080/ping; done

The middleware stack mirrors the snippet in SECURITY.md.

Jump to

Keyboard shortcuts

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