validate

package module
v0.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package validate is a goboot plugin that generates request validation from field-constraint annotations (github.com/zombocoder/goboot issue #34). It registers a small set of Bean-Validation-style field annotations, checks them against their field types during analysis, and emits a runtime.Validator that the app wires onto goboot's existing HTTP bind→validate step:

// @Required
// @Size(max=200)
Title string `json:"title"`

generates a validator that rejects a missing or over-long Title with a 400 Problem listing every offending field.

Register it in goboot.yaml:

plugins:
  - github.com/zombocoder/goboot/plugins/validate

then wire the generated validator in the composition root:

httpDeps.Validator = generated.NewValidator()

The plugin drives generation entirely from its own annotations via the deeper plugin API (model.Application.Declarations, §46.5) and the request types on the analyzed routes; it reads no struct tags of its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct{}

Plugin implements the AnnotationProvider, Analyzer, and Generator capabilities.

func New

func New() *Plugin

New constructs the validate plugin for injection into cli.Main.

func (*Plugin) Analyze

func (*Plugin) Analyze(app *model.Application) []*annotation.Diagnostic

Analyze validates the field-constraint annotations against their field types (§46.1): @Min/@Max on non-numeric fields, @Size on non-length types, @Pattern/@Email on non-strings, malformed @Size bounds, uncompilable @Pattern regexes, and constraints on non-request types (which won't be enforced). It never mutates the model.

func (*Plugin) Annotations

func (*Plugin) Annotations() []*annotation.Definition

Annotations registers the field-constraint annotations so the compiler recognizes them instead of reporting them as unknown.

func (*Plugin) Generate

func (*Plugin) Generate(app *model.Application) ([]plugin.File, error)

Generate emits the request validator from the resolved constraints (§46.1). It emits nothing when no request field carries a constraint. Diagnostics are surfaced by Analyze, so Generate only renders the enforceable rules.

func (*Plugin) Name

func (*Plugin) Name() string

Name identifies the plugin within a host.

func (*Plugin) Version

func (*Plugin) Version() string

Version is the plugin's own version.

Jump to

Keyboard shortcuts

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