2016-02-25 22:59:38 +00:00
|
|
|
package pathmatch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
internalErrorMessagePrefix = "Internal Error: "
|
|
|
|
)
|
|
|
|
|
2019-06-21 04:35:33 +00:00
|
|
|
type InternalError interface {
|
2016-02-25 22:59:38 +00:00
|
|
|
error
|
2019-06-21 04:35:33 +00:00
|
|
|
InternalError()
|
2016-02-25 22:59:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 04:35:33 +00:00
|
|
|
// internalInternalError is the only underlying implementation that fits the
|
|
|
|
// InternalError interface, in this library.
|
|
|
|
type internalInternalError struct {
|
2016-02-25 22:59:38 +00:00
|
|
|
msg string
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:35:33 +00:00
|
|
|
// newInternalError creates a new internalInternalError (struct) and
|
|
|
|
// returns it as a InternalError (interface).
|
|
|
|
func newInternalError(format string, a ...interface{}) InternalError {
|
2016-02-25 22:59:38 +00:00
|
|
|
msg := fmt.Sprintf(format, a...)
|
|
|
|
|
2019-06-21 04:35:33 +00:00
|
|
|
err := internalInternalError{
|
2016-02-25 22:59:38 +00:00
|
|
|
msg:msg,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &err
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:35:33 +00:00
|
|
|
// Error method is necessary to satisfy the 'error' interface (and the InternalError
|
2016-02-25 22:59:38 +00:00
|
|
|
// interface).
|
2019-06-21 04:35:33 +00:00
|
|
|
func (err *internalInternalError) Error() string {
|
2016-02-25 22:59:38 +00:00
|
|
|
var buffer bytes.Buffer
|
|
|
|
|
|
|
|
buffer.WriteString(internalErrorMessagePrefix)
|
|
|
|
buffer.WriteString(err.msg)
|
|
|
|
|
|
|
|
return buffer.String()
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:35:33 +00:00
|
|
|
// InternalError 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:35:33 +00:00
|
|
|
func (err *internalInternalError) InternalError() {
|
2016-02-25 22:59:38 +00:00
|
|
|
// Nothing here.
|
|
|
|
}
|