renamed "UnsupportedArgumentTypeComplainer" to "UnsupportedArgumentType"
parent
59a54f4c9e
commit
1af788fb28
|
@ -84,7 +84,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, UnsupportedArgumentTypeComplainer,
|
// NotEnoughArgumentsComplainer, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
|
||||||
// and StructFieldWrongTypeComplainer.
|
// and StructFieldWrongTypeComplainer.
|
||||||
//
|
//
|
||||||
// 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:"
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errExpectedAPointerToAStruct = newUnsupportedArgumentTypeComplainer("Expected a pointer to a struct, but wasn't.")
|
errExpectedAPointerToAStruct = newUnsupportedArgumentType("Expected a pointer to a struct, but wasn't.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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
|
continue
|
||||||
}
|
}
|
||||||
case UnsupportedArgumentTypeComplainer:
|
case UnsupportedArgumentType:
|
||||||
if expected, actual := unsupportedArgumentType, test.ExpectedFit; expected != actual {
|
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
|
continue
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,32 +1,24 @@
|
||||||
package pathmatch
|
package pathmatch
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type UnsupportedArgumentType interface {
|
||||||
type UnsupportedArgumentTypeComplainer interface {
|
|
||||||
BadRequestComplainer
|
BadRequestComplainer
|
||||||
UnsupportedArgumentTypeComplainer()
|
UnsupportedArgumentType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// internalUnsupportedIndexedArgumentTypeComplainer is the only underlying implementation that fits the
|
// internalUnsupportedIndexedArgumentTypeComplainer is the only underlying implementation that fits the
|
||||||
// UnsupportedArgumentTypeComplainer interface, in this library.
|
// UnsupportedArgumentType interface, in this library.
|
||||||
type internalUnsupportedIndexedArgumentTypeComplainer struct {
|
type internalUnsupportedIndexedArgumentTypeComplainer struct {
|
||||||
argumentIndex int
|
argumentIndex int
|
||||||
argumentType string
|
argumentType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// newUnsupportedIndexedArgumentTypeComplainer creates a new internalUnsupportedIndexedArgumentTypeComplainer (struct) and
|
// newUnsupportedIndexedArgumentTypeComplainer creates a new internalUnsupportedIndexedArgumentTypeComplainer (struct) and
|
||||||
// returns it as a UnsupportedArgumentTypeComplainer (interface).
|
// returns it as a UnsupportedArgumentType (interface).
|
||||||
func newUnsupportedIndexedArgumentTypeComplainer(argumentIndex int, argumentType string) UnsupportedArgumentTypeComplainer {
|
func newUnsupportedIndexedArgumentTypeComplainer(argumentIndex int, argumentType string) UnsupportedArgumentType {
|
||||||
err := internalUnsupportedIndexedArgumentTypeComplainer{
|
err := internalUnsupportedIndexedArgumentTypeComplainer{
|
||||||
argumentIndex:argumentIndex,
|
argumentIndex:argumentIndex,
|
||||||
argumentType:argumentType,
|
argumentType:argumentType,
|
||||||
|
@ -35,9 +27,8 @@ func newUnsupportedIndexedArgumentTypeComplainer(argumentIndex int, argumentType
|
||||||
return &err
|
return &err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error method is necessary to satisfy the 'error' interface (and the
|
// Error method is necessary to satisfy the 'error' interface (and the
|
||||||
// UnsupportedArgumentTypeComplainer interface).
|
// UnsupportedArgumentType interface).
|
||||||
func (err *internalUnsupportedIndexedArgumentTypeComplainer) Error() string {
|
func (err *internalUnsupportedIndexedArgumentTypeComplainer) Error() string {
|
||||||
s := fmt.Sprintf("Bad Request: Type of argument #%d (%s) is unsupported.", err.argumentIndex, err.argumentType)
|
s := fmt.Sprintf("Bad Request: Type of argument #%d (%s) is unsupported.", err.argumentIndex, err.argumentType)
|
||||||
if "string" == err.argumentType {
|
if "string" == err.argumentType {
|
||||||
|
@ -46,62 +37,51 @@ func (err *internalUnsupportedIndexedArgumentTypeComplainer) Error() string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 *internalUnsupportedIndexedArgumentTypeComplainer) BadRequestComplainer() {
|
func (err *internalUnsupportedIndexedArgumentTypeComplainer) BadRequestComplainer() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnsupportedArgumentType method is necessary to satisfy the 'UnsupportedArgumentType' interface.
|
||||||
// UnsupportedArgumentTypeComplainer method is necessary to satisfy the 'UnsupportedArgumentTypeComplainer' 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 *internalUnsupportedIndexedArgumentTypeComplainer) UnsupportedArgumentTypeComplainer() {
|
func (err *internalUnsupportedIndexedArgumentTypeComplainer) UnsupportedArgumentType() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// internalUnsupportedArgumentType is the only underlying implementation that fits the
|
||||||
|
// UnsupportedArgumentType interface, in this library.
|
||||||
|
type internalUnsupportedArgumentType struct {
|
||||||
|
|
||||||
|
|
||||||
// internalUnsupportedArgumentTypeComplainer is the only underlying implementation that fits the
|
|
||||||
// UnsupportedArgumentTypeComplainer interface, in this library.
|
|
||||||
type internalUnsupportedArgumentTypeComplainer struct {
|
|
||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newUnsupportedArgumentType creates a new internalUnsupportedArgumentType (struct) and
|
||||||
// newUnsupportedArgumentTypeComplainer creates a new internalUnsupportedArgumentTypeComplainer (struct) and
|
// returns it as a UnsupportedArgumentType (interface).
|
||||||
// returns it as a UnsupportedArgumentTypeComplainer (interface).
|
func newUnsupportedArgumentType(format string, a ...interface{}) UnsupportedArgumentType {
|
||||||
func newUnsupportedArgumentTypeComplainer(format string, a ...interface{}) UnsupportedArgumentTypeComplainer {
|
|
||||||
msg := fmt.Sprintf(format, a...)
|
msg := fmt.Sprintf(format, a...)
|
||||||
|
|
||||||
err := internalUnsupportedArgumentTypeComplainer{
|
err := internalUnsupportedArgumentType{
|
||||||
msg:msg,
|
msg:msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &err
|
return &err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error method is necessary to satisfy the 'error' interface (and the
|
// Error method is necessary to satisfy the 'error' interface (and the
|
||||||
// UnsupportedArgumentTypeComplainer interface).
|
// UnsupportedArgumentType interface).
|
||||||
func (err *internalUnsupportedArgumentTypeComplainer) Error() string {
|
func (err *internalUnsupportedArgumentType) Error() string {
|
||||||
|
|
||||||
return fmt.Sprintf("Bad Request: Unsupported Argument Type: %s", err.msg)
|
return fmt.Sprintf("Bad Request: Unsupported Argument Type: %s", err.msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 *internalUnsupportedArgumentTypeComplainer) BadRequestComplainer() {
|
func (err *internalUnsupportedArgumentType) BadRequestComplainer() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnsupportedArgumentType method is necessary to satisfy the 'UnsupportedArgumentType' interface.
|
||||||
// UnsupportedArgumentTypeComplainer method is necessary to satisfy the 'UnsupportedArgumentTypeComplainer' 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 *internalUnsupportedArgumentTypeComplainer) UnsupportedArgumentTypeComplainer() {
|
func (err *internalUnsupportedArgumentType) UnsupportedArgumentType() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue