{"modulePath":"github.com/go-openapi/runtime/docs/examples","version":"v0.33.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package main\n\nCommand validation backs the snippets on the doc-site \"Validation hooks\" page. Each type below is the source of a \\`{{\\\u003c code region=\"...\" \u003e}}\\` include; the package as a whole compiles and lints so the snippets cannot rot silently.\n\n\\`go run .\\` exercises the validators against canned inputs.\n\n## Types\n\n```go\ntype DateRange struct {\n\tFrom strfmt.Date `json:\"from\"`\n\tTo   strfmt.Date `json:\"to\"`\n}\n```\nDateRange illustrates a cross-field invariant on a hand-written type.\n\n```go\nfunc (d DateRange) Validate(_ strfmt.Registry) error\n```\nValidate enforces that To is not before From. The strfmt.Registry argument is unused here because the rule does not involve any registered string format.\n\n```go\ntype MyRequest struct {\n\tOnBehalfOf string `json:\"onBehalfOf\"`\n}\n```\nMyRequest is a hand-written request type that demonstrates a context-aware validation rule.\n\n```go\nfunc (r MyRequest) ContextValidate(ctx context.Context, _ strfmt.Registry) error\n```\nContextValidate enforces that on\\_behalf\\_of is only set when the request context carries an authenticated user.\n\n","path":"github.com/go-openapi/runtime/docs/examples/core/validation","name":"main","synopsis":"Command validation backs the snippets on the doc-site \"Validation hooks\" page.","isRedistributable":true}
