mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00:00
Add debug flag
This commit is contained in:
parent
061d31829d
commit
1f29574118
3 changed files with 31 additions and 0 deletions
24
handlers.go
24
handlers.go
|
@ -63,6 +63,9 @@ func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
|
|||
// CheckConfig returns a http.HandlerFunc that checks whether a configuration exists.
|
||||
func CheckConfig(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("CheckConfig()")
|
||||
}
|
||||
config := filepath.Join(c.path, "config")
|
||||
st, err := os.Stat(config)
|
||||
if err != nil {
|
||||
|
@ -77,6 +80,9 @@ func CheckConfig(c *Context) http.HandlerFunc {
|
|||
// GetConfig returns a http.HandlerFunc that allows for a config to be retrieved.
|
||||
func GetConfig(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("GetConfig()")
|
||||
}
|
||||
config := filepath.Join(c.path, "config")
|
||||
bytes, err := ioutil.ReadFile(config)
|
||||
if err != nil {
|
||||
|
@ -91,6 +97,9 @@ func GetConfig(c *Context) http.HandlerFunc {
|
|||
// SaveConfig returns a http.HandlerFunc that allows for a config to be saved.
|
||||
func SaveConfig(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("SaveConfig()")
|
||||
}
|
||||
config := filepath.Join(c.path, "config")
|
||||
bytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
|
@ -109,6 +118,9 @@ func SaveConfig(c *Context) http.HandlerFunc {
|
|||
// ListBlobs returns a http.HandlerFunc that lists all blobs of a given type in an arbitrary order.
|
||||
func ListBlobs(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("ListBlobs()")
|
||||
}
|
||||
vars := strings.Split(r.RequestURI, "/")
|
||||
dir := vars[1]
|
||||
path := filepath.Join(c.path, dir)
|
||||
|
@ -149,6 +161,9 @@ func ListBlobs(c *Context) http.HandlerFunc {
|
|||
// CheckBlob returns a http.HandlerFunc that tests whether a blob exists and returns 200, if it does, or 404 otherwise.
|
||||
func CheckBlob(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("CheckBlob()")
|
||||
}
|
||||
vars := strings.Split(r.RequestURI, "/")
|
||||
dir := vars[1]
|
||||
name := vars[2]
|
||||
|
@ -171,6 +186,9 @@ func CheckBlob(c *Context) http.HandlerFunc {
|
|||
// GetBlob returns a http.HandlerFunc that retrieves a blob from the repository.
|
||||
func GetBlob(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("GetBlob()")
|
||||
}
|
||||
vars := strings.Split(r.RequestURI, "/")
|
||||
dir := vars[1]
|
||||
name := vars[2]
|
||||
|
@ -194,6 +212,9 @@ func GetBlob(c *Context) http.HandlerFunc {
|
|||
// SaveBlob returns a http.HandlerFunc that saves a blob to the repository.
|
||||
func SaveBlob(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("SaveBlob()")
|
||||
}
|
||||
vars := strings.Split(r.RequestURI, "/")
|
||||
dir := vars[1]
|
||||
name := vars[2]
|
||||
|
@ -249,6 +270,9 @@ func SaveBlob(c *Context) http.HandlerFunc {
|
|||
// DeleteBlob returns a http.HandlerFunc that deletes a blob from the repository.
|
||||
func DeleteBlob(c *Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if *debug {
|
||||
log.Println("DeleteBlob()")
|
||||
}
|
||||
vars := strings.Split(r.RequestURI, "/")
|
||||
dir := vars[1]
|
||||
name := vars[2]
|
||||
|
|
2
main.go
2
main.go
|
@ -9,6 +9,8 @@ import (
|
|||
"runtime/pprof"
|
||||
)
|
||||
|
||||
var debug = flag.Bool("debug", false, "output debug messages")
|
||||
|
||||
func setupRoutes(path string) *Router {
|
||||
context := &Context{path}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
@ -114,6 +115,10 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
uri := r.RequestURI
|
||||
path := strings.Split(uri, "/")
|
||||
|
||||
if *debug {
|
||||
log.Printf("%s %s", method, uri)
|
||||
}
|
||||
|
||||
ROUTE:
|
||||
for _, route := range router.routes[method] {
|
||||
if len(route.path) != len(path) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue