2016-02-25 22:59:38 +00:00
|
|
|
package pathmatch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2019-06-21 04:38:18 +00:00
|
|
|
type NotEnoughArguments interface {
|
2019-06-21 04:31:53 +00:00
|
|
|
BadRequest
|
2019-06-21 04:38:18 +00:00
|
|
|
NotEnoughArguments()
|
2016-02-25 22:59:38 +00:00
|
|
|
|
|
|
|
ExpectedAtLeast() int
|
|
|
|
Actual() int
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:38:18 +00:00
|
|
|
// internalNotEnoughArguments is the only underlying implementation that fits the
|
|
|
|
// NotEnoughArguments interface, in this library.
|
|
|
|
type internalNotEnoughArguments struct {
|
2016-02-25 22:59:38 +00:00
|
|
|
expectedAtLeast int
|
|
|
|
actual int
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:38:18 +00:00
|
|
|
// newNotEnoughArguments creates a new internalNotEnoughArguments (struct) and
|
|
|
|
// returns it as a NotEnoughArguments (interface).
|
|
|
|
func newNotEnoughArguments(expectedAtLeast int, actual int) NotEnoughArguments {
|
|
|
|
err := internalNotEnoughArguments{
|
2016-02-25 22:59:38 +00:00
|
|
|
expectedAtLeast:expectedAtLeast,
|
|
|
|
actual:actual,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error method is necessary to satisfy the 'error' interface (and the
|
2019-06-21 04:38:18 +00:00
|
|
|
// NotEnoughArguments interface).
|
|
|
|
func (err *internalNotEnoughArguments) Error() string {
|
2016-02-25 22:59:38 +00:00
|
|
|
plural := ""
|
|
|
|
if 1 < err.expectedAtLeast {
|
|
|
|
plural = "s"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("Bad Request: Not enough arguments. Expected at least %d argument%s, but actually got %d.", err.expectedAtLeast, plural, err.actual)
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:31:53 +00:00
|
|
|
// BadRequest method is necessary to satisfy the 'BadRequest' 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:38:18 +00:00
|
|
|
func (err *internalNotEnoughArguments) BadRequest() {
|
2016-02-25 22:59:38 +00:00
|
|
|
// Nothing here.
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:38:18 +00:00
|
|
|
// NotEnoughArguments method is necessary to satisfy the 'NotEnoughArguments' 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:38:18 +00:00
|
|
|
func (err *internalNotEnoughArguments) NotEnoughArguments() {
|
2016-02-25 22:59:38 +00:00
|
|
|
// Nothing here.
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:38:18 +00:00
|
|
|
func (err *internalNotEnoughArguments) ExpectedAtLeast() int {
|
2016-02-25 22:59:38 +00:00
|
|
|
return err.expectedAtLeast
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:38:18 +00:00
|
|
|
func (err *internalNotEnoughArguments) Actual() int {
|
2016-02-25 22:59:38 +00:00
|
|
|
return err.actual
|
|
|
|
}
|