renamed "UnsupportedArgumentTypeComplainer" to "UnsupportedArgumentType"

master
Charles Iliya Krempeaux 2019-06-20 21:20:17 -07:00
parent 59a54f4c9e
commit 1af788fb28
4 changed files with 24 additions and 44 deletions

View File

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

View File

@ -10,7 +10,7 @@ import (
var (
errExpectedAPointerToAStruct = newUnsupportedArgumentTypeComplainer("Expected a pointer to a struct, but wasn't.")
errExpectedAPointerToAStruct = newUnsupportedArgumentType("Expected a pointer to a struct, but wasn't.")
)

View File

@ -356,9 +356,9 @@ func TestSetFail(t *testing.T) {
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"NotEnoughArgumentsComplainer\" interface, but actually did: %T.", testNumber, err)
continue
}
case UnsupportedArgumentTypeComplainer:
case UnsupportedArgumentType:
if expected, actual := unsupportedArgumentType, test.ExpectedFit; expected != actual {
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"UnsupportedArgumentTypeComplainer\" interface, but actually did: %T.", testNumber, err)
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"UnsupportedArgumentType\" interface, but actually did: %T.", testNumber, err)
continue
}
default:

View File

@ -1,32 +1,24 @@
package pathmatch
import (
"fmt"
)
type UnsupportedArgumentTypeComplainer interface {
type UnsupportedArgumentType interface {
BadRequestComplainer
UnsupportedArgumentTypeComplainer()
UnsupportedArgumentType()
}
// internalUnsupportedIndexedArgumentTypeComplainer is the only underlying implementation that fits the
// UnsupportedArgumentTypeComplainer interface, in this library.
// UnsupportedArgumentType interface, in this library.
type internalUnsupportedIndexedArgumentTypeComplainer struct {
argumentIndex int
argumentType string
}
// newUnsupportedIndexedArgumentTypeComplainer creates a new internalUnsupportedIndexedArgumentTypeComplainer (struct) and
// returns it as a UnsupportedArgumentTypeComplainer (interface).
func newUnsupportedIndexedArgumentTypeComplainer(argumentIndex int, argumentType string) UnsupportedArgumentTypeComplainer {
// returns it as a UnsupportedArgumentType (interface).
func newUnsupportedIndexedArgumentTypeComplainer(argumentIndex int, argumentType string) UnsupportedArgumentType {
err := internalUnsupportedIndexedArgumentTypeComplainer{
argumentIndex:argumentIndex,
argumentType:argumentType,
@ -35,9 +27,8 @@ func newUnsupportedIndexedArgumentTypeComplainer(argumentIndex int, argumentType
return &err
}
// Error method is necessary to satisfy the 'error' interface (and the
// UnsupportedArgumentTypeComplainer interface).
// UnsupportedArgumentType interface).
func (err *internalUnsupportedIndexedArgumentTypeComplainer) Error() string {
s := fmt.Sprintf("Bad Request: Type of argument #%d (%s) is unsupported.", err.argumentIndex, err.argumentType)
if "string" == err.argumentType {
@ -46,62 +37,51 @@ func (err *internalUnsupportedIndexedArgumentTypeComplainer) Error() string {
return s
}
// BadRequestComplainer method is necessary to satisfy the 'BadRequestComplainer' interface.
// It exists to make this error type detectable in a Go type-switch.
func (err *internalUnsupportedIndexedArgumentTypeComplainer) BadRequestComplainer() {
// Nothing here.
}
// UnsupportedArgumentTypeComplainer method is necessary to satisfy the 'UnsupportedArgumentTypeComplainer' interface.
// UnsupportedArgumentType method is necessary to satisfy the 'UnsupportedArgumentType' interface.
// It exists to make this error type detectable in a Go type-switch.
func (err *internalUnsupportedIndexedArgumentTypeComplainer) UnsupportedArgumentTypeComplainer() {
func (err *internalUnsupportedIndexedArgumentTypeComplainer) UnsupportedArgumentType() {
// Nothing here.
}
// internalUnsupportedArgumentTypeComplainer is the only underlying implementation that fits the
// UnsupportedArgumentTypeComplainer interface, in this library.
type internalUnsupportedArgumentTypeComplainer struct {
// internalUnsupportedArgumentType is the only underlying implementation that fits the
// UnsupportedArgumentType interface, in this library.
type internalUnsupportedArgumentType struct {
msg string
}
// newUnsupportedArgumentTypeComplainer creates a new internalUnsupportedArgumentTypeComplainer (struct) and
// returns it as a UnsupportedArgumentTypeComplainer (interface).
func newUnsupportedArgumentTypeComplainer(format string, a ...interface{}) UnsupportedArgumentTypeComplainer {
// newUnsupportedArgumentType creates a new internalUnsupportedArgumentType (struct) and
// returns it as a UnsupportedArgumentType (interface).
func newUnsupportedArgumentType(format string, a ...interface{}) UnsupportedArgumentType {
msg := fmt.Sprintf(format, a...)
err := internalUnsupportedArgumentTypeComplainer{
err := internalUnsupportedArgumentType{
msg:msg,
}
return &err
}
// Error method is necessary to satisfy the 'error' interface (and the
// UnsupportedArgumentTypeComplainer interface).
func (err *internalUnsupportedArgumentTypeComplainer) Error() string {
// UnsupportedArgumentType interface).
func (err *internalUnsupportedArgumentType) Error() string {
return fmt.Sprintf("Bad Request: Unsupported Argument Type: %s", err.msg)
}
// BadRequestComplainer method is necessary to satisfy the 'BadRequestComplainer' interface.
// It exists to make this error type detectable in a Go type-switch.
func (err *internalUnsupportedArgumentTypeComplainer) BadRequestComplainer() {
func (err *internalUnsupportedArgumentType) BadRequestComplainer() {
// Nothing here.
}
// UnsupportedArgumentTypeComplainer method is necessary to satisfy the 'UnsupportedArgumentTypeComplainer' interface.
// UnsupportedArgumentType method is necessary to satisfy the 'UnsupportedArgumentType' interface.
// It exists to make this error type detectable in a Go type-switch.
func (err *internalUnsupportedArgumentTypeComplainer) UnsupportedArgumentTypeComplainer() {
func (err *internalUnsupportedArgumentType) UnsupportedArgumentType() {
// Nothing here.
}