Documentation
¶
Overview ¶
Package main demonstrates where go-codex shines in a comment moderation use case: a single codec definition simultaneously escapes HTML, enforces length limits, and documents the schema — all derived from one value.
The key insight:
SafeTextCodec // transform: html.EscapeString on decode
.Refine(validate.NonEmptyString) // validate: reject empty
.Refine(validate.MaxLen(500)) // validate: reject too-long
.WithTitle("Body") // document: field name
.WithDescription("...") // document: human description
One codec = escaping + validation + OpenAPI schema. No separate validation function, no separate schema definition, no risk of them drifting apart.
Run with: go run ./examples/html-sanitize
Click to show internal directories.
Click to hide internal directories.