Documentation
¶
Overview ¶
Package paramvalidation validates handler parameter structs (path, query, signals) and route-to-path consistency.
Index ¶
- Variables
- func IsDispatchParam(f *ast.Field) bool
- func IsFormParam(f *ast.Field) bool
- func IsFormVar(f *types.Var) bool
- func IsPathParam(f *ast.Field) bool
- func IsQueryParam(f *ast.Field) bool
- func IsSessionParam(f *ast.Field) bool
- func IsSessionTokenParam(f *ast.Field) bool
- func IsSignalsParam(f *ast.Field) bool
- func ValidateDispatchFunc(f *ast.Field, info *types.Info, eventTypeNames map[string]struct{}, ...) ([]string, error)
- func ValidateFormStruct(st *types.Struct, fset *token.FileSet) (hasFileFields bool, errs []error)
- func ValidatePathAgainstRoute(h *model.Handler, recv, method string) error
- func ValidatePathStruct(f *ast.Field, info *types.Info, recv, method string) error
- func ValidateQueryStruct(f *ast.Field, info *types.Info, recv, method string) error
- func ValidateSignalsStruct(f *ast.Field, info *types.Info, recv, method string) error
- type ErrorDispatchMustReturnError
- type ErrorDispatchNoParams
- type ErrorDispatchParamNotEvent
- type ErrorFormFieldDuplicateTag
- type ErrorFormFieldMissingTag
- type ErrorFormFieldUnexported
- type ErrorFormFieldUnsupportedType
- type ErrorPathFieldDuplicateTag
- type ErrorPathFieldEmptyTag
- type ErrorPathFieldMissingTag
- type ErrorQueryFieldDuplicateTag
- type ErrorQueryFieldEmptyTag
- type ErrorQueryFieldInvalidTagName
- type ErrorQueryFieldMissingTag
- type ErrorSignalsFieldDuplicateTag
- type ErrorSignalsFieldEmptyTag
- type ErrorSignalsFieldMissingTag
Constants ¶
This section is empty.
Variables ¶
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.
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.
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.
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.
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 ¶
IsDispatchParam reports whether the AST field is named "dispatch".
func IsFormParam ¶
IsFormParam reports whether the AST field represents a form parameter (named "form").
func IsFormVar ¶
IsFormVar reports whether the types.Var represents a form parameter (named "form" with a struct underlying type).
func IsPathParam ¶
IsPathParam reports whether the AST field is named "path".
func IsQueryParam ¶
IsQueryParam reports whether the AST field is named "query".
func IsSessionParam ¶
IsSessionParam reports whether the AST field is named "session".
func IsSessionTokenParam ¶
IsSessionTokenParam reports whether the AST field is named "sessionToken".
func IsSignalsParam ¶
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 ¶
ValidatePathAgainstRoute checks that every path struct field tag matches a route variable and vice versa.
func ValidatePathStruct ¶
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 ¶
ValidateQueryStruct validates that a query parameter is a struct with exported fields each carrying a `query:"..."` 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 (e *ErrorDispatchMustReturnError) ASTPos() token.Pos
func (*ErrorDispatchMustReturnError) Error ¶
func (e *ErrorDispatchMustReturnError) Error() string
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 (e *ErrorDispatchParamNotEvent) Error() string
func (*ErrorDispatchParamNotEvent) Is ¶
func (e *ErrorDispatchParamNotEvent) Is(target error) bool
type ErrorFormFieldDuplicateTag ¶
ErrorFormFieldDuplicateTag is ErrFormFieldDuplicateTag with context.
func (*ErrorFormFieldDuplicateTag) ASTPos ¶
func (e *ErrorFormFieldDuplicateTag) ASTPos() token.Pos
func (*ErrorFormFieldDuplicateTag) Error ¶
func (e *ErrorFormFieldDuplicateTag) Error() string
func (*ErrorFormFieldDuplicateTag) Unwrap ¶
func (e *ErrorFormFieldDuplicateTag) Unwrap() error
type ErrorFormFieldMissingTag ¶
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 ¶
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 ¶
ErrorFormFieldUnsupportedType is ErrFormFieldUnsupportedType with context.
func (*ErrorFormFieldUnsupportedType) ASTPos ¶
func (e *ErrorFormFieldUnsupportedType) ASTPos() token.Pos
func (*ErrorFormFieldUnsupportedType) Error ¶
func (e *ErrorFormFieldUnsupportedType) Error() string
func (*ErrorFormFieldUnsupportedType) Unwrap ¶
func (e *ErrorFormFieldUnsupportedType) Unwrap() error
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 (e *ErrorPathFieldDuplicateTag) Error() string
func (*ErrorPathFieldDuplicateTag) Unwrap ¶
func (e *ErrorPathFieldDuplicateTag) Unwrap() error
type ErrorPathFieldEmptyTag ¶
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 ¶
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 (e *ErrorQueryFieldDuplicateTag) ASTPos() token.Pos
func (*ErrorQueryFieldDuplicateTag) Error ¶
func (e *ErrorQueryFieldDuplicateTag) Error() string
func (*ErrorQueryFieldDuplicateTag) Unwrap ¶
func (e *ErrorQueryFieldDuplicateTag) Unwrap() error
type ErrorQueryFieldEmptyTag ¶
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 (e *ErrorQueryFieldInvalidTagName) ASTPos() token.Pos
func (*ErrorQueryFieldInvalidTagName) Error ¶
func (e *ErrorQueryFieldInvalidTagName) Error() string
func (*ErrorQueryFieldInvalidTagName) Unwrap ¶
func (e *ErrorQueryFieldInvalidTagName) Unwrap() error
type ErrorQueryFieldMissingTag ¶
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 (e *ErrorSignalsFieldDuplicateTag) ASTPos() token.Pos
func (*ErrorSignalsFieldDuplicateTag) Error ¶
func (e *ErrorSignalsFieldDuplicateTag) Error() string
func (*ErrorSignalsFieldDuplicateTag) Unwrap ¶
func (e *ErrorSignalsFieldDuplicateTag) Unwrap() error
type ErrorSignalsFieldEmptyTag ¶
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 (e *ErrorSignalsFieldMissingTag) ASTPos() token.Pos
func (*ErrorSignalsFieldMissingTag) Error ¶
func (e *ErrorSignalsFieldMissingTag) Error() string
func (*ErrorSignalsFieldMissingTag) Unwrap ¶
func (e *ErrorSignalsFieldMissingTag) Unwrap() error