renamed "StructFieldWrongTypeComplainer" to "StructFieldWrongType"

master
Charles Iliya Krempeaux 2019-06-20 21:24:04 -07:00
parent 3d9d73798d
commit 2932ec74cc
3 changed files with 15 additions and 21 deletions

View File

@ -85,7 +85,7 @@ package pathmatch
// //
// Note that one can get more specific than just a BadRequestComplainer. For example: // Note that one can get more specific than just a BadRequestComplainer. For example:
// NotEnoughArgumentsComplainer, PatternSyntaxErrorComplainer, UnsupportedArgumentType, // NotEnoughArgumentsComplainer, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
// and StructFieldWrongTypeComplainer. // and StructFieldWrongType.
// //
// To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequestComplainer:" // To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequestComplainer:"
// in the type switch. For example: // in the type switch. For example:

View File

@ -72,7 +72,7 @@ func (pattern *internalPattern) MatchAndLoad(path string, strct interface{}) (bo
needle = " is not assignable to type " needle = " is not assignable to type "
if strings.Contains(s, needle) { if strings.Contains(s, needle) {
err = newStructFieldWrongTypeComplainer(matchName) err = newStructFieldWrongType(matchName)
return return
} }
} }

View File

@ -1,40 +1,36 @@
package pathmatch package pathmatch
import ( import (
"bytes" "bytes"
"fmt" "fmt"
) )
const structFieldWrongTypeMessagePrefix = "Bad Request: Wrong type for match " const structFieldWrongTypeMessagePrefix = "Bad Request: Wrong type for match "
type StructFieldWrongType interface {
type StructFieldWrongTypeComplainer interface {
BadRequestComplainer BadRequestComplainer
MatchName() string MatchName() string
} }
// internalStructFieldWrongTypeComplainer is the only underlying implementation that fits the // internalStructFieldWrongType is the only underlying implementation that fits the
// StructFieldWrongTypeComplainer interface, in this library. // StructFieldWrongType interface, in this library.
type internalStructFieldWrongTypeComplainer struct { type internalStructFieldWrongType struct {
matchName string matchName string
} }
// newStructFieldWrongTypeComplainer creates a new internalStructFieldWrongTypeComplainer (struct) and // newStructFieldWrongType creates a new internalStructFieldWrongType (struct) and
// returns it as a StructFieldWrongTypeComplainer (interface). // returns it as a StructFieldWrongType (interface).
func newStructFieldWrongTypeComplainer(matchName string) StructFieldWrongTypeComplainer { func newStructFieldWrongType(matchName string) StructFieldWrongType {
err := internalStructFieldWrongTypeComplainer{ err := internalStructFieldWrongType{
matchName:matchName, matchName:matchName,
} }
return &err return &err
} }
// Error method is necessary to satisfy the 'error' interface (and the StructFieldWrongType
// Error method is necessary to satisfy the 'error' interface (and the StructFieldWrongTypeComplainer
// interface). // interface).
func (err *internalStructFieldWrongTypeComplainer) Error() string { func (err *internalStructFieldWrongType) Error() string {
var buffer bytes.Buffer var buffer bytes.Buffer
buffer.WriteString(structFieldWrongTypeMessagePrefix) buffer.WriteString(structFieldWrongTypeMessagePrefix)
@ -43,15 +39,13 @@ func (err *internalStructFieldWrongTypeComplainer) Error() string {
return buffer.String() return buffer.String()
} }
// BadRequestComplainer method is necessary to satisfy the 'BadRequestComplainer' interface. // BadRequestComplainer method is necessary to satisfy the 'BadRequestComplainer' interface.
// It exists to make this error type detectable in a Go type-switch. // It exists to make this error type detectable in a Go type-switch.
func (err *internalStructFieldWrongTypeComplainer) BadRequestComplainer() { func (err *internalStructFieldWrongType) BadRequestComplainer() {
// Nothing here. // Nothing here.
} }
// DependencyName method is necessary to satisfy the 'StructFieldWrongType' interface.
// DependencyName method is necessary to satisfy the 'StructFieldWrongTypeComplainer' interface. func (err *internalStructFieldWrongType) MatchName() string {
func (err *internalStructFieldWrongTypeComplainer) MatchName() string {
return err.matchName return err.matchName
} }