html-sanitize

command
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 8 Imported by: 0

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

Jump to

Keyboard shortcuts

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