Documentation ¶
Index ¶
- Constants
- Variables
- func RouteParams(ctx context.Context) map[string]string
- type Client
- type Handler
- type Middleware
- type Request
- type Response
- type ResponseReader
- type Router
- func (r Router) Handle(ctx context.Context, request *Request) *Response
- func (r Router) Handler() Handler
- func (r Router) Match(request *Request) (Handler, map[string]string)
- func (r *Router) Mount(prefix string, subrouter *Router)
- func (r *Router) Route(pattern string, handler Handler)
- func (r *Router) Use(mw Middleware)
- type Server
- type ServerProtocol
- type Status
Constants ¶
const DefaultMaxRedirects int = 5
Variables ¶
var ExceededMaxRedirects = errors.New("Client: exceeded MaxRedirects")
var RouteParamsKey = routeParamsKeyType{}
Functions ¶
func RouteParams ¶
RouteParams gathers captured path parameters from the request context.
If the context doesn't contain a parameter map, it returns nil. If Router was used but no parameters were captured in the pattern, it returns a non-nil empty map.
Types ¶
type Client ¶ added in v1.1.0
type Client struct { MaxRedirects int // contains filtered or unexported fields }
Client is a multi-protocol client which handles all protocols known to sliderule.
func NewClient ¶ added in v1.1.0
NewClient builds a Client object.
tlsConf may be nil, in which case gemini requests connections will not be made with any client certificate.
func (Client) Fetch ¶ added in v1.1.0
Fetch collects a resource from a URL including following any redirects.
type Handler ¶
func FallthroughHandler ¶
FallthroughHandler builds a handler which tries multiple child handlers.
The returned handler will invoke each of the passed-in handlers in order, stopping when it receives a non-nil response.
func HandlerFunc ¶
HandlerFunc is a wrapper to allow using a function as a Handler.
func VirtualHosts ¶ added in v1.1.0
VirtualHosts builds a handler which dispatches to site handlers by hostname.
The 'catchall' argument may be used to specify a handler for use when no hostname match is found. If the catchall is nil and no match is found, the VirtualHosts handler returns a nil response.
type Middleware ¶
type Middleware = types.Middleware
func Filter ¶
Filter builds a middleware which only calls the wrapped Handler under a condition.
When the condition function returns false it instead invokes the test-failure handler. The failure handler may also be nil, in which case the final handler will return a nil response whenever the condition fails.
type ResponseReader ¶
type ResponseReader = types.ResponseReader
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router stores a mapping of request path patterns to handlers.
Pattern may begin with "/" and then contain slash-delimited segments.
- Segments containing a colon (:) are wildcards and will match any path segment at that location. It may optionally have a word after the colon, which will be the parameter name the path segment is captured into. It may also optionally have text before the colon, in which case the pattern will not match unless the request path segment contains that prefix.
- Segments beginning with asterisk (*) are remainder wildcards. This must come last and will capture any remainder of the path. It may have a name after the asterisk which will be the parameter name.
- Any other segment in the pattern must match a path segment exactly.
These patterns do not match any path which shares a prefix, rather then full path must match a pattern. If you want to only match a prefix of the path you can end the pattern with a *remainder segment.
The zero value is a usable Router which will fail to match any request path.
func (Router) Handle ¶ added in v1.4.0
Handle implements Handler
If no route matches, Handle returns a nil response. Captured path parameters will be stored in the context passed into the handler and can be retrieved with RouteParams().
func (Router) Handler ¶
Handler builds a Handler
It is only here for compatibility because Router implements Handler directly.
func (Router) Match ¶
Match returns the matched handler and captured path parameters, or (nil, nil).
The returned handlers will be wrapped with any middleware attached to the router.
func (*Router) Mount ¶
Mount attaches a sub-router to handle path suffixes after an initial prefix pattern.
The prefix pattern may include segment :wildcards, but no *remainder segment. The mounted sub-router should have patterns which only include the portion of the path after whatever was matched by the prefix pattern.
The root pattern ("/") in the sub-router will become a route which may or may not end with a forward slash.
func (*Router) Use ¶
func (r *Router) Use(mw Middleware)
Use attaches a middleware to the router.
Any routes set on the router will have their handlers decorated by the attached middlewares in reverse order (the first middleware attached will be the outer-most: first to see requests and the last to see responses).
Use will panic if Route or Mount have already been called on the router - middlewares must be set before any routes.
type ServerProtocol ¶ added in v1.6.0
type ServerProtocol = types.ServerProtocol
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Contrib contains sub-packages with specific functionality for small web servers.
|
Contrib contains sub-packages with specific functionality for small web servers. |
examples
|
|
The gemini package contains everything needed for building clients and servers on the gemini protocol.
|
The gemini package contains everything needed for building clients and servers on the gemini protocol. |
gemtext
The gemtext package contains a gemtext AST and parser.
|
The gemtext package contains a gemtext AST and parser. |
tools
|
|