2015-01-13 14:43:45 -05:00
|
|
|
// Package middleware includes a variety of middleware for
|
|
|
|
// the servers to use, according to their configuration.
|
|
|
|
package middleware
|
|
|
|
|
2015-01-19 01:11:21 -05:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
2015-01-13 14:43:45 -05:00
|
|
|
|
2015-01-19 01:11:21 -05:00
|
|
|
type (
|
|
|
|
// Generator represents the outer layer of a middleware that
|
|
|
|
// parses tokens to configure the middleware instance.
|
2015-01-30 00:02:17 -05:00
|
|
|
Generator func(Controller) (Middleware, error)
|
2015-01-19 01:11:21 -05:00
|
|
|
|
|
|
|
// Middleware is the middle layer which represents the traditional
|
|
|
|
// idea of middleware: it is passed the next HandlerFunc in the chain
|
|
|
|
// and returns the inner layer, which is the actual HandlerFunc.
|
|
|
|
Middleware func(http.HandlerFunc) http.HandlerFunc
|
|
|
|
|
2015-01-30 00:02:17 -05:00
|
|
|
// Controller is the type which middleware generators use to access
|
|
|
|
// tokens and the server and any other information they need to
|
|
|
|
// configure themselves.
|
|
|
|
Controller interface {
|
2015-01-19 01:11:21 -05:00
|
|
|
Next() bool
|
|
|
|
NextArg() bool
|
|
|
|
NextLine() bool
|
2015-01-21 14:09:49 -05:00
|
|
|
NextBlock() bool
|
2015-01-19 01:11:21 -05:00
|
|
|
Val() string
|
2015-01-21 19:51:47 -05:00
|
|
|
Args(...*string) bool
|
2015-01-30 00:02:17 -05:00
|
|
|
ArgErr() error
|
|
|
|
Err(string) error
|
2015-01-19 01:11:21 -05:00
|
|
|
Startup(func() error)
|
|
|
|
Root() string
|
|
|
|
Host() string
|
|
|
|
Port() string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Path represents a URI path, maybe with pattern characters.
|
|
|
|
type Path string
|
|
|
|
|
|
|
|
// Path matching will probably not always be a direct
|
|
|
|
// comparison; this method assures that paths can be
|
|
|
|
// easily matched.
|
|
|
|
func (p Path) Matches(other string) bool {
|
|
|
|
return strings.HasPrefix(string(p), other)
|
|
|
|
}
|