rest-server/handlers/data.go

55 lines
1.1 KiB
Go
Raw Normal View History

2015-08-11 14:14:07 +02:00
package handlers
import (
"fmt"
"net/http"
2015-08-11 14:52:42 +02:00
"os"
2015-08-11 14:14:07 +02:00
"path/filepath"
"github.com/bchapuis/restic-server/config"
)
func HeadData(w http.ResponseWriter, r *http.Request) {
repo, err := ExtractRepository(r)
if err != nil {
http.Error(w, "403 invalid repository", 403)
return
}
id, err := ExtractID(r)
if err != nil {
http.Error(w, "403 invalid ID", 403)
return
}
2015-08-11 14:52:42 +02:00
file := filepath.Join(config.DataPath(repo), id.String())
2015-08-11 14:14:07 +02:00
if _, err := os.Stat(file); err != nil {
http.Error(w, "404 repository not found", 404)
return
}
}
func GetData(w http.ResponseWriter, r *http.Request) {
repo, err := ExtractRepository(r)
if err != nil {
http.Error(w, "403 invalid repository", 403)
return
}
id, err := ExtractID(r)
if err != nil {
http.Error(w, "403 invalid ID", 403)
return
}
2015-08-11 14:52:42 +02:00
file := filepath.Join(config.DataPath(repo), id.String())
2015-08-11 14:14:07 +02:00
if _, err := os.Stat(file); err != nil {
http.Error(w, "404 repository not found", 404)
return
}
}
func PostData(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "data")
}
func DeleteData(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "data")
}