Add bucket info handler
Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
92b039fa5e
commit
cea8f9d4ca
3 changed files with 46 additions and 72 deletions
40
api/handler/info.go
Normal file
40
api/handler/info.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/nspcc-dev/neofs-s3-gate/api"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (h *handler) GetBucketLocationHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
bkt = mux.Vars(r)["bucket"]
|
||||
rid = api.GetRequestID(r.Context())
|
||||
)
|
||||
|
||||
if _, err := h.obj.GetBucketInfo(r.Context(), bkt); err != nil {
|
||||
h.log.Error("something went wrong",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
|
||||
api.WriteErrorResponse(r.Context(), w, api.Error{
|
||||
Code: api.GetAPIError(api.ErrInternalError).Code,
|
||||
Description: err.Error(),
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
|
||||
return
|
||||
} else if err = api.EncodeToResponse(w, LocationResponse{Location: ""}); err != nil {
|
||||
h.log.Error("could not write response",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
|
||||
api.WriteErrorResponse(r.Context(), w, api.Error{
|
||||
Code: api.GetAPIError(api.ErrInternalError).Code,
|
||||
Description: err.Error(),
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue