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"
yaml "gopkg.in/yaml.v2"
"novit.nc/direktil/local-server/pkg/clustersconfig"
)

View File

@ -16,7 +16,7 @@ import (
var (
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")
)
@ -32,6 +32,10 @@ func main() {
func handleHTTP(w http.ResponseWriter, req *http.Request) {
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)
if err != nil {
writeErr(err, w)
@ -43,10 +47,6 @@ func handleHTTP(w http.ResponseWriter, req *http.Request) {
return
}
l := fmt.Sprintf("%s %s", req.Method, filePath)
log.Print(l)
defer log.Print(l, " done")
switch req.Method {
case "GET":
sha1Hex, err := hashOf(filePath)
@ -58,8 +58,9 @@ func handleHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Set("X-Content-SHA1", sha1Hex)
http.ServeFile(w, req, filePath)
//case "POST":
// // TODO upload
case "POST":
// TODO upload
http.Error(w, "not implemented", http.StatusNotImplemented)
default:
http.NotFound(w, req)