mirror of
https://github.com/restic/rest-server.git
synced 2026-04-13 21:51:52 -07:00
Update with changes from github.com/restic/restic tree
Uncompilable right now, due to bad import paths.
This commit is contained in:
22
router.go
22
router.go
@@ -1,3 +1,5 @@
|
||||
// +build go1.4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -6,83 +8,103 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Route is a handler for a path that was already split.
|
||||
type Route struct {
|
||||
path []string
|
||||
handler http.Handler
|
||||
}
|
||||
|
||||
// Router maps HTTP methods to a slice of Route handlers.
|
||||
type Router struct {
|
||||
routes map[string][]Route
|
||||
}
|
||||
|
||||
// NewRouter creates a new Router and returns a pointer to it.
|
||||
func NewRouter() *Router {
|
||||
return &Router{make(map[string][]Route)}
|
||||
}
|
||||
|
||||
// Options registers handler for path with method "OPTIONS".
|
||||
func (router *Router) Options(path string, handler http.Handler) {
|
||||
router.Handle("OPTIONS", path, handler)
|
||||
}
|
||||
|
||||
// OptionsFunc registers handler for path with method "OPTIONS".
|
||||
func (router *Router) OptionsFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("OPTIONS", path, handler)
|
||||
}
|
||||
|
||||
// Get registers handler for path with method "GET".
|
||||
func (router *Router) Get(path string, handler http.Handler) {
|
||||
router.Handle("GET", path, handler)
|
||||
}
|
||||
|
||||
// GetFunc registers handler for path with method "GET".
|
||||
func (router *Router) GetFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("GET", path, handler)
|
||||
}
|
||||
|
||||
// Head registers handler for path with method "HEAD".
|
||||
func (router *Router) Head(path string, handler http.Handler) {
|
||||
router.Handle("HEAD", path, handler)
|
||||
}
|
||||
|
||||
// HeadFunc registers handler for path with method "HEAD".
|
||||
func (router *Router) HeadFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("HEAD", path, handler)
|
||||
}
|
||||
|
||||
// Post registers handler for path with method "POST".
|
||||
func (router *Router) Post(path string, handler http.Handler) {
|
||||
router.Handle("POST", path, handler)
|
||||
}
|
||||
|
||||
// PostFunc registers handler for path with method "POST".
|
||||
func (router *Router) PostFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("POST", path, handler)
|
||||
}
|
||||
|
||||
// Put registers handler for path with method "PUT".
|
||||
func (router *Router) Put(path string, handler http.Handler) {
|
||||
router.Handle("PUT", path, handler)
|
||||
}
|
||||
|
||||
// PutFunc registers handler for path with method "PUT".
|
||||
func (router *Router) PutFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("PUT", path, handler)
|
||||
}
|
||||
|
||||
// Delete registers handler for path with method "DELETE".
|
||||
func (router *Router) Delete(path string, handler http.Handler) {
|
||||
router.Handle("DELETE", path, handler)
|
||||
}
|
||||
|
||||
// DeleteFunc registers handler for path with method "DELETE".
|
||||
func (router *Router) DeleteFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("DELETE", path, handler)
|
||||
}
|
||||
|
||||
// Trace registers handler for path with method "TRACE".
|
||||
func (router *Router) Trace(path string, handler http.Handler) {
|
||||
router.Handle("TRACE", path, handler)
|
||||
}
|
||||
|
||||
// TraceFunc registers handler for path with method "TRACE".
|
||||
func (router *Router) TraceFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("TRACE", path, handler)
|
||||
}
|
||||
|
||||
// Connect registers handler for path with method "Connect".
|
||||
func (router *Router) Connect(path string, handler http.Handler) {
|
||||
router.Handle("Connect", path, handler)
|
||||
}
|
||||
|
||||
// ConnectFunc registers handler for path with method "Connect".
|
||||
func (router *Router) ConnectFunc(path string, handler http.HandlerFunc) {
|
||||
router.Handle("Connect", path, handler)
|
||||
}
|
||||
|
||||
// Handle registers a http.Handler for method and uri
|
||||
func (router *Router) Handle(method string, uri string, handler http.Handler) {
|
||||
routes := router.routes[method]
|
||||
path := strings.Split(uri, "/")
|
||||
|
||||
Reference in New Issue
Block a user