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 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 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 ErrorPathFieldDuplicateTag
- type ErrorPathFieldEmptyTag
- type ErrorPathFieldMissingTag
- type ErrorQueryFieldDuplicateTag
- type ErrorQueryFieldEmptyTag
- 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", ) )
Query 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 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 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 ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (e *ErrorDispatchMustReturnError) ASTPos() token.Pos
func (*ErrorDispatchMustReturnError) Error ¶ added in v0.4.0
func (e *ErrorDispatchMustReturnError) Error() string
func (*ErrorDispatchMustReturnError) Is ¶ added in v0.4.0
func (e *ErrorDispatchMustReturnError) Is(target error) bool
type ErrorDispatchNoParams ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (e *ErrorDispatchNoParams) ASTPos() token.Pos
func (*ErrorDispatchNoParams) Error ¶ added in v0.4.0
func (e *ErrorDispatchNoParams) Error() string
func (*ErrorDispatchNoParams) Is ¶ added in v0.4.0
func (e *ErrorDispatchNoParams) Is(target error) bool
type ErrorDispatchParamNotEvent ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (e *ErrorDispatchParamNotEvent) ASTPos() token.Pos
func (*ErrorDispatchParamNotEvent) Error ¶ added in v0.4.0
func (e *ErrorDispatchParamNotEvent) Error() string
func (*ErrorDispatchParamNotEvent) Is ¶ added in v0.4.0
func (e *ErrorDispatchParamNotEvent) Is(target error) bool
type ErrorPathFieldDuplicateTag ¶ added in v0.2.3
type ErrorPathFieldDuplicateTag struct {
FieldName string
TagValue string
Recv string
Method string
Pos token.Pos
}
ErrorPathFieldDuplicateTag is ErrPathFieldDuplicateTag with suggestion context.
func (*ErrorPathFieldDuplicateTag) ASTPos ¶ added in v0.4.0
func (e *ErrorPathFieldDuplicateTag) ASTPos() token.Pos
func (*ErrorPathFieldDuplicateTag) Error ¶ added in v0.2.3
func (e *ErrorPathFieldDuplicateTag) Error() string
func (*ErrorPathFieldDuplicateTag) Unwrap ¶ added in v0.2.3
func (e *ErrorPathFieldDuplicateTag) Unwrap() error
type ErrorPathFieldEmptyTag ¶ added in v0.2.3
ErrorPathFieldEmptyTag is ErrPathFieldEmptyTag with suggestion context.
func (*ErrorPathFieldEmptyTag) ASTPos ¶ added in v0.4.0
func (e *ErrorPathFieldEmptyTag) ASTPos() token.Pos
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
ErrorPathFieldMissingTag is ErrPathFieldMissingTag with suggestion context.
func (*ErrorPathFieldMissingTag) ASTPos ¶ added in v0.4.0
func (e *ErrorPathFieldMissingTag) ASTPos() token.Pos
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
Pos token.Pos
}
ErrorQueryFieldDuplicateTag is ErrQueryFieldDuplicateTag with suggestion context.
func (*ErrorQueryFieldDuplicateTag) ASTPos ¶ added in v0.4.0
func (e *ErrorQueryFieldDuplicateTag) ASTPos() token.Pos
func (*ErrorQueryFieldDuplicateTag) Error ¶ added in v0.2.3
func (e *ErrorQueryFieldDuplicateTag) Error() string
func (*ErrorQueryFieldDuplicateTag) Unwrap ¶ added in v0.2.3
func (e *ErrorQueryFieldDuplicateTag) Unwrap() error
type ErrorQueryFieldEmptyTag ¶ added in v0.2.3
ErrorQueryFieldEmptyTag is ErrQueryFieldEmptyTag with suggestion context.
func (*ErrorQueryFieldEmptyTag) ASTPos ¶ added in v0.4.0
func (e *ErrorQueryFieldEmptyTag) ASTPos() token.Pos
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
ErrorQueryFieldMissingTag is ErrQueryFieldMissingTag with suggestion context.
func (*ErrorQueryFieldMissingTag) ASTPos ¶ added in v0.4.0
func (e *ErrorQueryFieldMissingTag) ASTPos() token.Pos
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
Pos token.Pos
}
ErrorSignalsFieldDuplicateTag is ErrSignalsFieldDuplicateTag with suggestion context.
func (*ErrorSignalsFieldDuplicateTag) ASTPos ¶ added in v0.4.0
func (e *ErrorSignalsFieldDuplicateTag) ASTPos() token.Pos
func (*ErrorSignalsFieldDuplicateTag) Error ¶ added in v0.2.3
func (e *ErrorSignalsFieldDuplicateTag) Error() string
func (*ErrorSignalsFieldDuplicateTag) Unwrap ¶ added in v0.2.3
func (e *ErrorSignalsFieldDuplicateTag) Unwrap() error
type ErrorSignalsFieldEmptyTag ¶ added in v0.2.3
ErrorSignalsFieldEmptyTag is ErrSignalsFieldEmptyTag with suggestion context.
func (*ErrorSignalsFieldEmptyTag) ASTPos ¶ added in v0.4.0
func (e *ErrorSignalsFieldEmptyTag) ASTPos() token.Pos
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
Pos token.Pos
}
ErrorSignalsFieldMissingTag is ErrSignalsFieldMissingTag with suggestion context.
func (*ErrorSignalsFieldMissingTag) ASTPos ¶ added in v0.4.0
func (e *ErrorSignalsFieldMissingTag) ASTPos() token.Pos
func (*ErrorSignalsFieldMissingTag) Error ¶ added in v0.2.0
func (e *ErrorSignalsFieldMissingTag) Error() string
func (*ErrorSignalsFieldMissingTag) Unwrap ¶ added in v0.2.0
func (e *ErrorSignalsFieldMissingTag) Unwrap() error