paramvalidation

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 9 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`,
	)
	ErrPathFieldNotString = errors.New(
		"path struct field must be of type string",
	)
	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`,
	)
)

Query 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",
	)
	ErrDispatchReturnCount = errors.New(
		"dispatch function must return " +
			"exactly one value",
	)
	ErrDispatchMustReturnError = errors.New(
		"dispatch function must return error",
	)
	ErrDispatchNoParams = errors.New(
		"dispatch function must have " +
			"at least one event parameter",
	)
	ErrDispatchParamNotEvent = errors.New(
		"dispatch function parameter " +
			"must be an event type",
	)
)

Dispatch parameter errors.

Functions

func IsDispatchParam

func IsDispatchParam(f *ast.Field) bool

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

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 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 string fields 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 ErrorPathFieldDuplicateTag added in v0.2.3

type ErrorPathFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
}

ErrorPathFieldDuplicateTag is ErrPathFieldDuplicateTag with suggestion context.

func (*ErrorPathFieldDuplicateTag) Error added in v0.2.3

func (*ErrorPathFieldDuplicateTag) Unwrap added in v0.2.3

func (e *ErrorPathFieldDuplicateTag) Unwrap() error

type ErrorPathFieldEmptyTag added in v0.2.3

type ErrorPathFieldEmptyTag struct {
	FieldName string
	Recv      string
	Method    string
}

ErrorPathFieldEmptyTag is ErrPathFieldEmptyTag with suggestion context.

func (*ErrorPathFieldEmptyTag) Error added in v0.2.3

func (e *ErrorPathFieldEmptyTag) Error() string

func (*ErrorPathFieldEmptyTag) Unwrap added in v0.2.3

func (e *ErrorPathFieldEmptyTag) Unwrap() error

type ErrorPathFieldMissingTag added in v0.2.0

type ErrorPathFieldMissingTag struct {
	FieldName string
	Recv      string
	Method    string
}

ErrorPathFieldMissingTag is ErrPathFieldMissingTag with suggestion context.

func (*ErrorPathFieldMissingTag) Error added in v0.2.0

func (e *ErrorPathFieldMissingTag) Error() string

func (*ErrorPathFieldMissingTag) Unwrap added in v0.2.0

func (e *ErrorPathFieldMissingTag) Unwrap() error

type ErrorQueryFieldDuplicateTag added in v0.2.3

type ErrorQueryFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
}

ErrorQueryFieldDuplicateTag is ErrQueryFieldDuplicateTag with suggestion context.

func (*ErrorQueryFieldDuplicateTag) Error added in v0.2.3

func (*ErrorQueryFieldDuplicateTag) Unwrap added in v0.2.3

func (e *ErrorQueryFieldDuplicateTag) Unwrap() error

type ErrorQueryFieldEmptyTag added in v0.2.3

type ErrorQueryFieldEmptyTag struct {
	FieldName string
	Recv      string
	Method    string
}

ErrorQueryFieldEmptyTag is ErrQueryFieldEmptyTag with suggestion context.

func (*ErrorQueryFieldEmptyTag) Error added in v0.2.3

func (e *ErrorQueryFieldEmptyTag) Error() string

func (*ErrorQueryFieldEmptyTag) Unwrap added in v0.2.3

func (e *ErrorQueryFieldEmptyTag) Unwrap() error

type ErrorQueryFieldMissingTag added in v0.2.0

type ErrorQueryFieldMissingTag struct {
	FieldName string
	Recv      string
	Method    string
}

ErrorQueryFieldMissingTag is ErrQueryFieldMissingTag with suggestion context.

func (*ErrorQueryFieldMissingTag) Error added in v0.2.0

func (e *ErrorQueryFieldMissingTag) Error() string

func (*ErrorQueryFieldMissingTag) Unwrap added in v0.2.0

func (e *ErrorQueryFieldMissingTag) Unwrap() error

type ErrorSignalsFieldDuplicateTag added in v0.2.3

type ErrorSignalsFieldDuplicateTag struct {
	FieldName string
	TagValue  string
	Recv      string
	Method    string
}

ErrorSignalsFieldDuplicateTag is ErrSignalsFieldDuplicateTag with suggestion context.

func (*ErrorSignalsFieldDuplicateTag) Error added in v0.2.3

func (*ErrorSignalsFieldDuplicateTag) Unwrap added in v0.2.3

type ErrorSignalsFieldEmptyTag added in v0.2.3

type ErrorSignalsFieldEmptyTag struct {
	FieldName string
	Recv      string
	Method    string
}

ErrorSignalsFieldEmptyTag is ErrSignalsFieldEmptyTag with suggestion context.

func (*ErrorSignalsFieldEmptyTag) Error added in v0.2.3

func (e *ErrorSignalsFieldEmptyTag) Error() string

func (*ErrorSignalsFieldEmptyTag) Unwrap added in v0.2.3

func (e *ErrorSignalsFieldEmptyTag) Unwrap() error

type ErrorSignalsFieldMissingTag added in v0.2.0

type ErrorSignalsFieldMissingTag struct {
	FieldName string
	Recv      string
	Method    string
}

ErrorSignalsFieldMissingTag is ErrSignalsFieldMissingTag with suggestion context.

func (*ErrorSignalsFieldMissingTag) Error added in v0.2.0

func (*ErrorSignalsFieldMissingTag) Unwrap added in v0.2.0

func (e *ErrorSignalsFieldMissingTag) Unwrap() error

Jump to

Keyboard shortcuts

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