2016-02-25 22:59:38 +00:00
package pathmatch
import (
"fmt"
)
2019-06-21 04:31:53 +00:00
// PatternSyntaxErrorComplainer is used to represent a specific kind of BadRequest error.
2016-02-25 22:59:38 +00:00
// Specifically, it represents a syntax error in the uncompiled pattern passed to the
// pathmatch.Compile() func.
//
// Example usage is as follows:
//
// pattern, err := pathmatch.Compile("/something/{there_is_a_syntax_error_in_this_pattern")
// if nil != err {
// switch err.(type) {
//
2019-06-21 04:31:53 +00:00
// 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!
2016-02-25 22:59:38 +00:00
//
// 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
//
2019-06-21 04:31:53 +00:00
// case pathmatch.BadRequest:
2016-02-25 22:59:38 +00:00
//
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
// return
//
2019-06-21 04:35:33 +00:00
// case pathmatch.InternalError:
2016-02-25 22:59:38 +00:00
//
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
// return
//
// default:
//
// fmt.Printf("Some kind of unexpected error happend: %v", err)
// return
// }
// }
type PatternSyntaxErrorComplainer interface {
2019-06-21 04:31:53 +00:00
BadRequest
2016-02-25 22:59:38 +00:00
PatternSyntaxErrorComplainer ( )
}
// internalPatternSyntaxErrorComplainer is the only underlying implementation that fits the
// PatternSyntaxErrorComplainer interface, in this library.
type internalPatternSyntaxErrorComplainer struct {
msg string
}
// newPatternSyntaxErrorComplainer creates a new internalPatternSyntaxErrorComplainer (struct) and
// returns it as a PatternSyntaxErrorComplainer (interface).
func newPatternSyntaxErrorComplainer ( format string , a ... interface { } ) PatternSyntaxErrorComplainer {
msg := fmt . Sprintf ( format , a ... )
err := internalPatternSyntaxErrorComplainer {
msg : msg ,
}
return & err
}
// Error method is necessary to satisfy the 'error' interface (and the
// PatternSyntaxErrorComplainer interface).
func ( err * internalPatternSyntaxErrorComplainer ) Error ( ) string {
s := fmt . Sprintf ( "Bad Request: Syntax Error: %s" , err . msg )
return s
}
2019-06-21 04:35:33 +00:00
// BadRequest method is necessary to satisfy the 'InternalError' interface.
2016-02-25 22:59:38 +00:00
// It exists to make this error type detectable in a Go type-switch.
2019-06-21 04:31:53 +00:00
func ( err * internalPatternSyntaxErrorComplainer ) BadRequest ( ) {
2016-02-25 22:59:38 +00:00
// Nothing here.
}
// PatternSyntaxErrorComplainer method is necessary to satisfy the 'PatternSyntaxErrorComplainer' interface.
// It exists to make this error type detectable in a Go type-switch.
func ( err * internalPatternSyntaxErrorComplainer ) PatternSyntaxErrorComplainer ( ) {
// Nothing here.
}