store: prepare upload

This commit is contained in:
Mikaël Cluseau 2019-10-16 16:16:15 +11:00
parent 4679da1c1e
commit 36e1367522
2 changed files with 9 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import (
"log" "log"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
"novit.nc/direktil/local-server/pkg/clustersconfig" "novit.nc/direktil/local-server/pkg/clustersconfig"
) )

View File

@ -16,7 +16,7 @@ import (
var ( var (
bind = flag.String("bind", ":8080", "Bind address") bind = flag.String("bind", ":8080", "Bind address")
uploadToken = flag.String("upload-token", "", "Upload token (not uploads allowed if empty)") uploadToken = flag.String("upload-token", "", "Upload token (no uploads allowed if empty)")
storeDir = flag.String("store-dir", "/srv/dkl-store", "Store directory") storeDir = flag.String("store-dir", "/srv/dkl-store", "Store directory")
) )
@ -32,6 +32,10 @@ func main() {
func handleHTTP(w http.ResponseWriter, req *http.Request) { func handleHTTP(w http.ResponseWriter, req *http.Request) {
filePath := filepath.Join(*storeDir, req.URL.Path) filePath := filepath.Join(*storeDir, req.URL.Path)
l := fmt.Sprintf("%s %s", req.Method, filePath)
log.Print(l)
defer log.Print(l, " done")
stat, err := os.Stat(filePath) stat, err := os.Stat(filePath)
if err != nil { if err != nil {
writeErr(err, w) writeErr(err, w)
@ -43,10 +47,6 @@ func handleHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
l := fmt.Sprintf("%s %s", req.Method, filePath)
log.Print(l)
defer log.Print(l, " done")
switch req.Method { switch req.Method {
case "GET": case "GET":
sha1Hex, err := hashOf(filePath) sha1Hex, err := hashOf(filePath)
@ -58,8 +58,9 @@ func handleHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Set("X-Content-SHA1", sha1Hex) w.Header().Set("X-Content-SHA1", sha1Hex)
http.ServeFile(w, req, filePath) http.ServeFile(w, req, filePath)
//case "POST": case "POST":
// // TODO upload // TODO upload
http.Error(w, "not implemented", http.StatusNotImplemented)
default: default:
http.NotFound(w, req) http.NotFound(w, req)