paramvalidation

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package paramvalidation validates handler parameter structs (path, query, signals) and route-to-path consistency.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPathParamNotStruct = errors.New(
		"path parameter must be an anonymous struct",
	)
	ErrPathFieldUnexported = errors.New(
		"path struct field must be exported",
	)
	ErrPathFieldMissingTag = errors.New(
		`path struct field must have a path:"..." tag`,
	)
	ErrPathFieldUnsupportedType = errors.New(
		"path struct field has unsupported type",
	)
	ErrPathFieldNotInRoute = errors.New(
		"path struct field tag does not match any route variable",
	)
	ErrPathMissingRouteVar = errors.New(
		"route variable has no matching path struct field",
	)
	ErrPathFieldDuplicateTag = errors.New(
		"path struct field has duplicate path tag value",
	)
	ErrPathFieldEmptyTag = errors.New(
		`path struct field path tag must have a non-empty name`,
	)
)

Path parameter errors.

View Source
var (
	ErrQueryParamNotStruct = errors.New(
		"query parameter must be a struct",
	)
	ErrQueryFieldUnexported = errors.New(
		"query struct field must be exported",
	)
	ErrQueryFieldMissingTag = errors.New(
		`query struct field must have a query:"..." tag`,
	)
	ErrQueryFieldDuplicateTag = errors.New(
		"query struct field has duplicate query tag value",
	)
	ErrQueryFieldEmptyTag = errors.New(
		`query struct field query tag must have a non-empty name`,
	)
	ErrQueryFieldUnsupportedType = errors.New(
		"query struct field has unsupported type",
	)
	ErrQueryFieldInvalidTagName = errors.New(
		"query struct field has invalid tag name " +
			"(must start with a letter, then letters/digits/underscores/dots/hyphens)",
	)
)

Query parameter errors.

View Source
var (
	ErrFormFieldUnexported = errors.New(
		"form field is unexported",
	)
	ErrFormFieldMissingTag = errors.New(
		`form field is missing "form" struct tag`,
	)
	ErrFormFieldDuplicateTag = errors.New(
		"duplicate form struct tag",
	)
	ErrFormFieldUnsupportedType = errors.New(
		"form field has unsupported type",
	)
)

Form parameter errors.

View Source
var (
	ErrSignalsParamNotStruct = errors.New(
		"signals parameter must be a struct",
	)
	ErrSignalsFieldUnexported = errors.New(
		"signals struct field must be exported",
	)
	ErrSignalsFieldMissingTag = errors.New(
		`signals struct field must have a json:"..." tag`,
	)
	ErrSignalsFieldDuplicateTag = errors.New(
		"signals struct field has duplicate json tag value",
	)
	ErrSignalsFieldEmptyTag = errors.New(
		`signals struct field json tag must have a non-empty name`,
	)
)

Signals parameter errors.

View Source
var (
	ErrDispatchParamNotFunc = errors.New(
		"dispatch parameter must be a function type",
	)
	ErrDispatchMustReturnError error = &ErrorDispatchMustReturnError{}
	ErrDispatchNoParams        error = &ErrorDispatchNoParams{}
	ErrDispatchParamNotEvent   error = &ErrorDispatchParamNotEvent{}
)

Dispatch parameter errors.

Functions

func IsDispatchParam

func IsDispatchParam(f *ast.Field) bool

IsDispatchParam reports whether the AST field is named "dispatch".

func IsFormParam

func IsFormParam(f *ast.Field) bool

IsFormParam reports whether the AST field represents a form parameter (named "form").

func IsFormVar

func IsFormVar(f *types.Var) bool

IsFormVar reports whether the types.Var represents a form parameter (named "form" with a struct underlying type).

func IsPathParam

func IsPathParam(f *ast.Field) bool

IsPathParam reports whether the AST field is named "path".

func IsQueryParam

func IsQueryParam(f *ast.Field) bool

IsQueryParam reports whether the AST field is named "query".

func IsSessionParam

func IsSessionParam(f *ast.Field) bool

IsSessionParam reports whether the AST field is named "session".

func IsSessionTokenParam

func IsSessionTokenParam(f *ast.Field) bool

IsSessionTokenParam reports whether the AST field is named "sessionToken".

func IsSignalsParam

func IsSignalsParam(f *ast.Field) bool

IsSignalsParam reports whether the AST field is named "signals".

func ValidateDispatchFunc

func ValidateDispatchFunc(
	f *ast.Field,
	info *types.Info,
	eventTypeNames map[string]struct{},
	recv, method string,
) ([]string, error)

ValidateDispatchFunc validates that a dispatch parameter is a function type with EventXXX parameters and a single error return. Returns the list of event type names.

func ValidateFormStruct

func ValidateFormStruct(
	st *types.Struct, fset *token.FileSet,
) (hasFileFields bool, errs []error)

ValidateFormStruct validates that a form struct has exported fields with `form:"..."` tags and supported types. It returns whether any fields are file upload types.

func ValidatePathAgainstRoute

func ValidatePathAgainstRoute(
	h *model.Handler, recv, method string,
) error

ValidatePathAgainstRoute checks that every path struct field tag matches a route variable and vice versa.

func ValidatePathStruct

func ValidatePathStruct(
	f *ast.Field, info *types.Info, recv, method string,
) error

ValidatePathStruct validates that a path parameter is an anonymous struct with exported fields of supported types (string, bool, integers, floats, or encoding.TextUnmarshaler) each carrying a `path:"..."` tag.

func ValidateQueryStruct

func ValidateQueryStruct(
	f *ast.Field, info *types.Info, recv, method string,
) error

ValidateQueryStruct validates that a query parameter is a struct with exported fields each carrying a `query:"..."` tag.

func ValidateSignalsStruct

func ValidateSignalsStruct(
	f *ast.Field, info *types.Info, recv, method string,
) error

ValidateSignalsStruct validates that a signals parameter is a struct with exported fields each carrying a `json:"..."` tag.

Types

type ErrorDispatchMustReturnError

type ErrorDispatchMustReturnError struct {
	Recv       string    // e.g. "PageFoo"
	MethodName string    // e.g. "GET"
	ParamTypes string    // e.g. "EventFoo, EventBar"
	Pos        token.Pos // position of the problematic return type or func keyword
}

ErrorDispatchMustReturnError is returned when a dispatch function's return type is not exactly `error`.

func (*ErrorDispatchMustReturnError) ASTPos

func (*ErrorDispatchMustReturnError) Error

func (*ErrorDispatchMustReturnError) Is

func (e *ErrorDispatchMustReturnError) Is(target error) bool

type ErrorDispatchNoParams

type ErrorDispatchNoParams struct {
	Recv       string    // e.g. "PageFoo"
	MethodName string    // e.g. "GET"
	Pos        token.Pos // position of the empty param list
}

ErrorDispatchNoParams is returned when a dispatch function has no parameters.

func (*ErrorDispatchNoParams) ASTPos

func (e *ErrorDispatchNoParams) ASTPos() token.Pos

func (*ErrorDispatchNoParams) Error

func (e *ErrorDispatchNoParams) Error() string

func (*ErrorDispatchNoParams) Is

func (e *ErrorDispatchNoParams) Is(target error) bool

type ErrorDispatchParamNotEvent

type ErrorDispatchParamNotEvent struct {
	Recv       string    // e.g. "PageFoo"
	MethodName string    // e.g. "GET"
	Pos        token.Pos // position of the non-event parameter type
}

ErrorDispatchParamNotEvent is returned when a dispatch function parameter is not an event type.

func (*ErrorDispatchParamNotEvent) ASTPos

func (e *ErrorDispatchParamNotEvent) ASTPos() token.Pos

func (*ErrorDispatchParamNotEvent) Error

func (*ErrorDispatchParamNotEvent) Is

func (e *ErrorDispatchParamNotEvent) Is(target error) bool

type ErrorFormFieldDuplicateTag

type ErrorFormFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Pos       token.Pos
}

ErrorFormFieldDuplicateTag is ErrFormFieldDuplicateTag with context.

func (*ErrorFormFieldDuplicateTag) ASTPos

func (e *ErrorFormFieldDuplicateTag) ASTPos() token.Pos

func (*ErrorFormFieldDuplicateTag) Error

func (*ErrorFormFieldDuplicateTag) Unwrap

func (e *ErrorFormFieldDuplicateTag) Unwrap() error

type ErrorFormFieldMissingTag

type ErrorFormFieldMissingTag struct {
	FieldName string
	Pos       token.Pos
}

ErrorFormFieldMissingTag is ErrFormFieldMissingTag with context.

func (*ErrorFormFieldMissingTag) ASTPos

func (e *ErrorFormFieldMissingTag) ASTPos() token.Pos

func (*ErrorFormFieldMissingTag) Error

func (e *ErrorFormFieldMissingTag) Error() string

func (*ErrorFormFieldMissingTag) Unwrap

func (e *ErrorFormFieldMissingTag) Unwrap() error

type ErrorFormFieldUnexported

type ErrorFormFieldUnexported struct {
	FieldName string
	Pos       token.Pos
}

ErrorFormFieldUnexported is ErrFormFieldUnexported with context.

func (*ErrorFormFieldUnexported) ASTPos

func (e *ErrorFormFieldUnexported) ASTPos() token.Pos

func (*ErrorFormFieldUnexported) Error

func (e *ErrorFormFieldUnexported) Error() string

func (*ErrorFormFieldUnexported) Unwrap

func (e *ErrorFormFieldUnexported) Unwrap() error

type ErrorFormFieldUnsupportedType

type ErrorFormFieldUnsupportedType struct {
	FieldName string
	Pos       token.Pos
}

ErrorFormFieldUnsupportedType is ErrFormFieldUnsupportedType with context.

func (*ErrorFormFieldUnsupportedType) ASTPos

func (*ErrorFormFieldUnsupportedType) Error

func (*ErrorFormFieldUnsupportedType) Unwrap

type ErrorPathFieldDuplicateTag

type ErrorPathFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorPathFieldDuplicateTag is ErrPathFieldDuplicateTag with suggestion context.

func (*ErrorPathFieldDuplicateTag) ASTPos

func (e *ErrorPathFieldDuplicateTag) ASTPos() token.Pos

func (*ErrorPathFieldDuplicateTag) Error

func (*ErrorPathFieldDuplicateTag) Unwrap

func (e *ErrorPathFieldDuplicateTag) Unwrap() error

type ErrorPathFieldEmptyTag

type ErrorPathFieldEmptyTag struct {
	FieldName string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorPathFieldEmptyTag is ErrPathFieldEmptyTag with suggestion context.

func (*ErrorPathFieldEmptyTag) ASTPos

func (e *ErrorPathFieldEmptyTag) ASTPos() token.Pos

func (*ErrorPathFieldEmptyTag) Error

func (e *ErrorPathFieldEmptyTag) Error() string

func (*ErrorPathFieldEmptyTag) Unwrap

func (e *ErrorPathFieldEmptyTag) Unwrap() error

type ErrorPathFieldMissingTag

type ErrorPathFieldMissingTag struct {
	FieldName string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorPathFieldMissingTag is ErrPathFieldMissingTag with suggestion context.

func (*ErrorPathFieldMissingTag) ASTPos

func (e *ErrorPathFieldMissingTag) ASTPos() token.Pos

func (*ErrorPathFieldMissingTag) Error

func (e *ErrorPathFieldMissingTag) Error() string

func (*ErrorPathFieldMissingTag) Unwrap

func (e *ErrorPathFieldMissingTag) Unwrap() error

type ErrorQueryFieldDuplicateTag

type ErrorQueryFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorQueryFieldDuplicateTag is ErrQueryFieldDuplicateTag with suggestion context.

func (*ErrorQueryFieldDuplicateTag) ASTPos

func (*ErrorQueryFieldDuplicateTag) Error

func (*ErrorQueryFieldDuplicateTag) Unwrap

func (e *ErrorQueryFieldDuplicateTag) Unwrap() error

type ErrorQueryFieldEmptyTag

type ErrorQueryFieldEmptyTag struct {
	FieldName string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorQueryFieldEmptyTag is ErrQueryFieldEmptyTag with suggestion context.

func (*ErrorQueryFieldEmptyTag) ASTPos

func (e *ErrorQueryFieldEmptyTag) ASTPos() token.Pos

func (*ErrorQueryFieldEmptyTag) Error

func (e *ErrorQueryFieldEmptyTag) Error() string

func (*ErrorQueryFieldEmptyTag) Unwrap

func (e *ErrorQueryFieldEmptyTag) Unwrap() error

type ErrorQueryFieldInvalidTagName

type ErrorQueryFieldInvalidTagName struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorQueryFieldInvalidTagName is ErrQueryFieldInvalidTagName with suggestion context.

func (*ErrorQueryFieldInvalidTagName) ASTPos

func (*ErrorQueryFieldInvalidTagName) Error

func (*ErrorQueryFieldInvalidTagName) Unwrap

type ErrorQueryFieldMissingTag

type ErrorQueryFieldMissingTag struct {
	FieldName string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorQueryFieldMissingTag is ErrQueryFieldMissingTag with suggestion context.

func (*ErrorQueryFieldMissingTag) ASTPos

func (e *ErrorQueryFieldMissingTag) ASTPos() token.Pos

func (*ErrorQueryFieldMissingTag) Error

func (e *ErrorQueryFieldMissingTag) Error() string

func (*ErrorQueryFieldMissingTag) Unwrap

func (e *ErrorQueryFieldMissingTag) Unwrap() error

type ErrorSignalsFieldDuplicateTag

type ErrorSignalsFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorSignalsFieldDuplicateTag is ErrSignalsFieldDuplicateTag with suggestion context.

func (*ErrorSignalsFieldDuplicateTag) ASTPos

func (*ErrorSignalsFieldDuplicateTag) Error

func (*ErrorSignalsFieldDuplicateTag) Unwrap

type ErrorSignalsFieldEmptyTag

type ErrorSignalsFieldEmptyTag struct {
	FieldName string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorSignalsFieldEmptyTag is ErrSignalsFieldEmptyTag with suggestion context.

func (*ErrorSignalsFieldEmptyTag) ASTPos

func (e *ErrorSignalsFieldEmptyTag) ASTPos() token.Pos

func (*ErrorSignalsFieldEmptyTag) Error

func (e *ErrorSignalsFieldEmptyTag) Error() string

func (*ErrorSignalsFieldEmptyTag) Unwrap

func (e *ErrorSignalsFieldEmptyTag) Unwrap() error

type ErrorSignalsFieldMissingTag

type ErrorSignalsFieldMissingTag struct {
	FieldName string
	Recv      string
	Method    string
	Pos       token.Pos
}

ErrorSignalsFieldMissingTag is ErrSignalsFieldMissingTag with suggestion context.

func (*ErrorSignalsFieldMissingTag) ASTPos

func (*ErrorSignalsFieldMissingTag) Error

func (*ErrorSignalsFieldMissingTag) Unwrap

func (e *ErrorSignalsFieldMissingTag) Unwrap() error

Jump to

Keyboard shortcuts

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