0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/middleware/middleware.go

91 lines
3.3 KiB
Go
Raw Normal View History

2015-01-30 00:14:31 -05:00
// Package middleware provides some types and functions common among middleware.
2015-01-13 14:43:45 -05:00
package middleware
2015-01-30 00:08:40 -05:00
import "net/http"
2015-01-13 14:43:45 -05:00
type (
// Generator represents the outer layer of a middleware that
// parses tokens to configure the middleware instance.
Generator func(Controller) (Middleware, error)
// 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-03-20 19:11:54 -05:00
// A Control provides structured access to tokens from a configuration file
// and also to properties of the server being configured. Middleware generators
// use a Controller to construct their middleware instance.
Controller interface {
2015-03-20 19:11:54 -05:00
// Next loads the next token. Returns true if a token
// was loaded; false otherwise. If false, all tokens
// have already been consumed.
Next() bool
2015-03-20 19:11:54 -05:00
// NextArg loads the next token if it is on the same
// line. Returns true if a token was loaded; false
// otherwise. If false, all tokens on the line have
// been consumed.
NextArg() bool
2015-03-20 19:11:54 -05:00
// NextLine loads the next token only if it is NOT on the same
// line as the current token, and returns true if a token was
// loaded; false otherwise. If false, there is not another token
// or it is on the same line.
NextLine() bool
2015-03-20 19:11:54 -05:00
2015-03-21 12:18:37 -05:00
// NextBlock can be used as the condition of a for loop
// to load the next token as long as it opens a block or
// is already in a block. It returns true if a token was
// loaded, or false when the block's closing curly brace
// was loaded and thus the block ended. Nested blocks are
// not (currently) supported.
2015-01-21 14:09:49 -05:00
NextBlock() bool
2015-03-20 19:11:54 -05:00
// Val gets the text of the current token.
Val() string
2015-03-20 19:11:54 -05:00
// Args is a convenience function that loads the next arguments
// (tokens on the same line) into an arbitrary number of strings
// pointed to in arguments. If there are fewer tokens available
// than string pointers, the remaining strings will not be changed
// and false will be returned. If there were enough tokens available
// to fill the arguments, then true will be returned.
2015-01-21 19:51:47 -05:00
Args(...*string) bool
2015-03-20 19:11:54 -05:00
2015-03-21 15:36:32 -05:00
// RemainingArgs loads any more arguments (tokens on the same line)
// into a slice and returns them. Open curly brace tokens also indicate
// the end of arguments, and the curly brace is not included in
// the return value nor is it loaded.
RemainingArgs() []string
2015-03-20 19:11:54 -05:00
// ArgErr returns an argument error, meaning that another
// argument was expected but not found. In other words,
// a line break, EOF, or open curly brace was encountered instead of
// an argument.
ArgErr() error
2015-03-20 19:11:54 -05:00
// Err generates a custom parse error with a message of msg.
Err(string) error
2015-03-20 19:11:54 -05:00
// Startup registers a function to execute when the server starts.
Startup(func() error)
2015-03-20 19:11:54 -05:00
// Shutdown registers a function to execute when the server exits.
Shutdown(func() error)
2015-03-20 19:11:54 -05:00
// Root returns the file path from which the server is serving.
Root() string
2015-03-20 19:11:54 -05:00
// Host returns the hostname the server is bound to.
Host() string
2015-03-20 19:11:54 -05:00
// Port returns the port that the server is listening on.
Port() string
2015-03-20 19:11:54 -05:00
// Context returns the path scope that the Controller is in.
// Note: This is not currently used, but may be in the future.
Context() Path
}
)