mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-20 08:14:03 +01:00
v0.5: dependencies update, EOF fix for PUT/POST /v1/file
This commit is contained in:
@@ -17,6 +17,7 @@ func NewHandler(cfg *config.Config) http.Handler {
|
||||
mux.HandleFunc("GET /v1/list/{what}", wrap(cfg, v1.List))
|
||||
mux.HandleFunc("GET /v1/file", v1.GetFileContent)
|
||||
mux.HandleFunc("GET /v1/file/{filename}", v1.GetFileContent)
|
||||
mux.HandleFunc("POST /v1/file/{filename}", v1.SetFileContent)
|
||||
mux.HandleFunc("PUT /v1/file/{filename}", v1.SetFileContent)
|
||||
mux.HandleFunc("GET /v1/stats", wrap(cfg, v1.Stats))
|
||||
return mux
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@@ -31,8 +32,7 @@ func SetFileContent(w http.ResponseWriter, r *http.Request) {
|
||||
U.HandleErr(w, r, U.ErrMissingKey("filename"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
content := make([]byte, r.ContentLength)
|
||||
_, err := E.Check(r.Body.Read(content))
|
||||
content, err := E.Check(io.ReadAll(r.Body))
|
||||
if err.IsNotNil() {
|
||||
U.HandleErr(w, r, err)
|
||||
return
|
||||
@@ -45,7 +45,7 @@ func SetFileContent(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err.IsNotNil() {
|
||||
U.HandleErr(w, r, err)
|
||||
U.HandleErr(w, r, err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user