mirror of
https://github.com/restic/rest-server.git
synced 2026-09-26 05:51:24 -07:00
Use goji.io pat package to extract params
This commit is contained in:
+11
-15
@@ -9,8 +9,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"goji.io/pat"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isHashed(dir string) bool {
|
func isHashed(dir string) bool {
|
||||||
@@ -113,8 +114,7 @@ func ListBlobs(w http.ResponseWriter, r *http.Request) {
|
|||||||
if *debug {
|
if *debug {
|
||||||
log.Println("ListBlobs()")
|
log.Println("ListBlobs()")
|
||||||
}
|
}
|
||||||
vars := strings.Split(r.RequestURI, "/")
|
dir := pat.Param(r, "type")
|
||||||
dir := vars[1]
|
|
||||||
path := filepath.Join(*path, dir)
|
path := filepath.Join(*path, dir)
|
||||||
|
|
||||||
items, err := ioutil.ReadDir(path)
|
items, err := ioutil.ReadDir(path)
|
||||||
@@ -154,9 +154,8 @@ func CheckBlob(w http.ResponseWriter, r *http.Request) {
|
|||||||
if *debug {
|
if *debug {
|
||||||
log.Println("CheckBlob()")
|
log.Println("CheckBlob()")
|
||||||
}
|
}
|
||||||
vars := strings.Split(r.RequestURI, "/")
|
dir := pat.Param(r, "type")
|
||||||
dir := vars[1]
|
name := pat.Param(r, "name")
|
||||||
name := vars[2]
|
|
||||||
|
|
||||||
if isHashed(dir) {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
@@ -177,9 +176,8 @@ func GetBlob(w http.ResponseWriter, r *http.Request) {
|
|||||||
if *debug {
|
if *debug {
|
||||||
log.Println("GetBlob()")
|
log.Println("GetBlob()")
|
||||||
}
|
}
|
||||||
vars := strings.Split(r.RequestURI, "/")
|
dir := pat.Param(r, "type")
|
||||||
dir := vars[1]
|
name := pat.Param(r, "name")
|
||||||
name := vars[2]
|
|
||||||
|
|
||||||
if isHashed(dir) {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
@@ -201,9 +199,8 @@ func SaveBlob(w http.ResponseWriter, r *http.Request) {
|
|||||||
if *debug {
|
if *debug {
|
||||||
log.Println("SaveBlob()")
|
log.Println("SaveBlob()")
|
||||||
}
|
}
|
||||||
vars := strings.Split(r.RequestURI, "/")
|
dir := pat.Param(r, "type")
|
||||||
dir := vars[1]
|
name := pat.Param(r, "name")
|
||||||
name := vars[2]
|
|
||||||
|
|
||||||
if dir == "keys" {
|
if dir == "keys" {
|
||||||
if _, err := os.Stat("keys"); err != nil && os.IsNotExist(err) {
|
if _, err := os.Stat("keys"); err != nil && os.IsNotExist(err) {
|
||||||
@@ -257,9 +254,8 @@ func DeleteBlob(w http.ResponseWriter, r *http.Request) {
|
|||||||
if *debug {
|
if *debug {
|
||||||
log.Println("DeleteBlob()")
|
log.Println("DeleteBlob()")
|
||||||
}
|
}
|
||||||
vars := strings.Split(r.RequestURI, "/")
|
dir := pat.Param(r, "type")
|
||||||
dir := vars[1]
|
name := pat.Param(r, "name")
|
||||||
name := vars[2]
|
|
||||||
|
|
||||||
if isHashed(dir) {
|
if isHashed(dir) {
|
||||||
name = filepath.Join(name[:2], name)
|
name = filepath.Join(name[:2], name)
|
||||||
|
|||||||
Reference in New Issue
Block a user