|
|
|
@ -3,7 +3,8 @@ package application
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"strconv"
|
|
|
|
|
// "io"
|
|
|
|
|
"caj-larsson/bog/domain"
|
|
|
|
|
"caj-larsson/bog/integration"
|
|
|
|
|
)
|
|
|
|
@ -41,23 +42,33 @@ func buildHttpMux(file_service domain.BogFileService) *http.ServeMux {
|
|
|
|
|
case "GET":
|
|
|
|
|
bog_file, err := file_service.OpenOutFile(ref)
|
|
|
|
|
|
|
|
|
|
if err == domain.ErrNotExists {
|
|
|
|
|
http.NotFound(w, r)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http.ServeContent(w, r, bog_file.Path(), bog_file.Modified(), bog_file)
|
|
|
|
|
|
|
|
|
|
case "POST":
|
|
|
|
|
fallthrough
|
|
|
|
|
case "PUT":
|
|
|
|
|
bog_file, err := file_service.CreateOrOpenInFile(ref)
|
|
|
|
|
|
|
|
|
|
size_str := r.Header["Content-Length"][0]
|
|
|
|
|
|
|
|
|
|
size, err := strconv.ParseInt(size_str, 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
w.WriteHeader(422)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
io.Copy(bog_file, r.Body)
|
|
|
|
|
bog_file.Close()
|
|
|
|
|
err = file_service.SaveFile(ref, r.Body, size)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
})
|
|
|
|
|