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 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`, ) 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.
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.
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", ) 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 ¶
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 string fields 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 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 (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) 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) 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 (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) 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) 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 (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) 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
ErrorSignalsFieldMissingTag is ErrSignalsFieldMissingTag with suggestion context.
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