renamed "PatternSyntaxErrorComplainer" to "PatternSyntaxError"
parent
d669c009fe
commit
87c495d123
|
@ -83,7 +83,7 @@ package pathmatch
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Note that one can get more specific than just a BadRequest. For example:
|
// Note that one can get more specific than just a BadRequest. For example:
|
||||||
// NotEnoughArguments, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
|
// NotEnoughArguments, PatternSyntaxError, UnsupportedArgumentType,
|
||||||
// and StructFieldWrongType.
|
// and StructFieldWrongType.
|
||||||
//
|
//
|
||||||
// To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequest:"
|
// To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequest:"
|
||||||
|
@ -93,7 +93,7 @@ package pathmatch
|
||||||
// if nil != err {
|
// if nil != err {
|
||||||
// switch err.(type) {
|
// switch err.(type) {
|
||||||
//
|
//
|
||||||
// case pathmatch.PatternSyntaxErrorComplainer: // ← Here we are detecting if the error returned was due to a syntax error, in the uncompiled pattern. Also note that it comes BEFORE the 'pathmatch.BadRequest' case; THAT IS IMPORTANT!
|
// case pathmatch.PatternSyntaxError: // ← Here we are detecting if the error returned was due to a syntax error, in the uncompiled pattern. Also note that it comes BEFORE the 'pathmatch.BadRequest' case; THAT IS IMPORTANT!
|
||||||
//
|
//
|
||||||
// fmt.Printf("The uncompiled pattern passed to pathmatch.Compile() had a syntax error in it. The error message describing the syntax error is....\n%s\n", err.Error())
|
// fmt.Printf("The uncompiled pattern passed to pathmatch.Compile() had a syntax error in it. The error message describing the syntax error is....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
|
|
@ -13,9 +13,9 @@ const (
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errMissingEndingRightBraceToMatchBeginningLeftBrace = newPatternSyntaxErrorComplainer(`Missing ending "}" (to match beginning "{").`)
|
errMissingEndingRightBraceToMatchBeginningLeftBrace = newPatternSyntaxError(`Missing ending "}" (to match beginning "{").`)
|
||||||
errSlashInsideOfBraces = newPatternSyntaxErrorComplainer(`"/" inside of "{...}".`)
|
errSlashInsideOfBraces = newPatternSyntaxError(`"/" inside of "{...}".`)
|
||||||
errLeftBraceInsideOfBraces = newPatternSyntaxErrorComplainer(`"{" inside of "{...}".`)
|
errLeftBraceInsideOfBraces = newPatternSyntaxError(`"{" inside of "{...}".`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func Compile(uncompiledPattern string) (Pattern, error) {
|
||||||
|
|
||||||
// Match names should be unique, within a pattern.
|
// Match names should be unique, within a pattern.
|
||||||
if _, ok := pattern.namesSet[bit]; ok {
|
if _, ok := pattern.namesSet[bit]; ok {
|
||||||
return nil, newPatternSyntaxErrorComplainer("Duplicate match name: %q.", bit)
|
return nil, newPatternSyntaxError("Duplicate match name: %q.", bit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// PatternSyntaxErrorComplainer is used to represent a specific kind of BadRequest error.
|
// PatternSyntaxError is used to represent a specific kind of BadRequest error.
|
||||||
// Specifically, it represents a syntax error in the uncompiled pattern passed to the
|
// Specifically, it represents a syntax error in the uncompiled pattern passed to the
|
||||||
// pathmatch.Compile() func.
|
// pathmatch.Compile() func.
|
||||||
//
|
//
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
// if nil != err {
|
// if nil != err {
|
||||||
// switch err.(type) {
|
// switch err.(type) {
|
||||||
//
|
//
|
||||||
// case pathmatch.PatternSyntaxErrorComplainer: // ← Here we are detecting if the error returned was due to a syntax error, in the uncompiled pattern. Also note that it comes BEFORE the 'pathmatch.BadRequest' case; THAT IS IMPORTANT!
|
// case pathmatch.PatternSyntaxError: // ← Here we are detecting if the error returned was due to a syntax error, in the uncompiled pattern. Also note that it comes BEFORE the 'pathmatch.BadRequest' case; THAT IS IMPORTANT!
|
||||||
//
|
//
|
||||||
// fmt.Printf("The uncompiled pattern passed to pathmatch.Compile() had a syntax error in it. The error message describing the syntax error is....\n%s\n", err.Error())
|
// fmt.Printf("The uncompiled pattern passed to pathmatch.Compile() had a syntax error in it. The error message describing the syntax error is....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
@ -37,25 +37,25 @@ import (
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
type PatternSyntaxErrorComplainer interface {
|
type PatternSyntaxError interface {
|
||||||
BadRequest
|
BadRequest
|
||||||
PatternSyntaxErrorComplainer()
|
PatternSyntaxError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internalPatternSyntaxErrorComplainer is the only underlying implementation that fits the
|
// internalPatternSyntaxError is the only underlying implementation that fits the
|
||||||
// PatternSyntaxErrorComplainer interface, in this library.
|
// PatternSyntaxError interface, in this library.
|
||||||
type internalPatternSyntaxErrorComplainer struct {
|
type internalPatternSyntaxError struct {
|
||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// newPatternSyntaxErrorComplainer creates a new internalPatternSyntaxErrorComplainer (struct) and
|
// newPatternSyntaxError creates a new internalPatternSyntaxError (struct) and
|
||||||
// returns it as a PatternSyntaxErrorComplainer (interface).
|
// returns it as a PatternSyntaxError (interface).
|
||||||
func newPatternSyntaxErrorComplainer(format string, a ...interface{}) PatternSyntaxErrorComplainer {
|
func newPatternSyntaxError(format string, a ...interface{}) PatternSyntaxError {
|
||||||
msg := fmt.Sprintf(format, a...)
|
msg := fmt.Sprintf(format, a...)
|
||||||
|
|
||||||
err := internalPatternSyntaxErrorComplainer{
|
err := internalPatternSyntaxError{
|
||||||
msg:msg,
|
msg:msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +64,8 @@ func newPatternSyntaxErrorComplainer(format string, a ...interface{}) PatternSyn
|
||||||
|
|
||||||
|
|
||||||
// Error method is necessary to satisfy the 'error' interface (and the
|
// Error method is necessary to satisfy the 'error' interface (and the
|
||||||
// PatternSyntaxErrorComplainer interface).
|
// PatternSyntaxError interface).
|
||||||
func (err *internalPatternSyntaxErrorComplainer) Error() string {
|
func (err *internalPatternSyntaxError) Error() string {
|
||||||
s := fmt.Sprintf("Bad Request: Syntax Error: %s", err.msg)
|
s := fmt.Sprintf("Bad Request: Syntax Error: %s", err.msg)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,13 @@ func (err *internalPatternSyntaxErrorComplainer) Error() string {
|
||||||
|
|
||||||
// BadRequest method is necessary to satisfy the 'InternalError' interface.
|
// BadRequest method is necessary to satisfy the 'InternalError' 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 *internalPatternSyntaxErrorComplainer) BadRequest() {
|
func (err *internalPatternSyntaxError) BadRequest() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// PatternSyntaxErrorComplainer method is necessary to satisfy the 'PatternSyntaxErrorComplainer' interface.
|
// PatternSyntaxError method is necessary to satisfy the 'PatternSyntaxError' 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 *internalPatternSyntaxErrorComplainer) PatternSyntaxErrorComplainer() {
|
func (err *internalPatternSyntaxError) PatternSyntaxError() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue