mirror of
https://github.com/ferdzo/fs.git
synced 2026-04-05 08:26:28 +00:00
Enhance API with health check endpoints and improve multipart upload management
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"fs/models"
|
||||
"fs/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
type s3APIError struct {
|
||||
@@ -21,6 +23,11 @@ var (
|
||||
Code: "InvalidArgument",
|
||||
Message: "Object key is required.",
|
||||
}
|
||||
s3ErrKeyTooLong = s3APIError{
|
||||
Status: http.StatusBadRequest,
|
||||
Code: "KeyTooLongError",
|
||||
Message: "Your key is too long.",
|
||||
}
|
||||
s3ErrNotImplemented = s3APIError{
|
||||
Status: http.StatusNotImplemented,
|
||||
Code: "NotImplemented",
|
||||
@@ -56,6 +63,16 @@ var (
|
||||
Code: "EntityTooSmall",
|
||||
Message: "Your proposed upload is smaller than the minimum allowed object size.",
|
||||
}
|
||||
s3ErrEntityTooLarge = s3APIError{
|
||||
Status: http.StatusRequestEntityTooLarge,
|
||||
Code: "EntityTooLarge",
|
||||
Message: "Your proposed upload exceeds the maximum allowed size.",
|
||||
}
|
||||
s3ErrTooManyDeleteObjects = s3APIError{
|
||||
Status: http.StatusBadRequest,
|
||||
Code: "MalformedXML",
|
||||
Message: "The request must contain no more than 1000 object identifiers.",
|
||||
}
|
||||
s3ErrInternal = s3APIError{
|
||||
Status: http.StatusInternalServerError,
|
||||
Code: "InternalError",
|
||||
@@ -121,6 +138,13 @@ func mapToS3Error(err error) s3APIError {
|
||||
}
|
||||
|
||||
func writeS3Error(w http.ResponseWriter, r *http.Request, apiErr s3APIError, resource string) {
|
||||
requestID := ""
|
||||
if r != nil {
|
||||
requestID = middleware.GetReqID(r.Context())
|
||||
if requestID != "" {
|
||||
w.Header().Set("x-amz-request-id", requestID)
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
w.WriteHeader(apiErr.Status)
|
||||
|
||||
@@ -129,9 +153,10 @@ func writeS3Error(w http.ResponseWriter, r *http.Request, apiErr s3APIError, res
|
||||
}
|
||||
|
||||
payload := models.S3ErrorResponse{
|
||||
Code: apiErr.Code,
|
||||
Message: apiErr.Message,
|
||||
Resource: resource,
|
||||
Code: apiErr.Code,
|
||||
Message: apiErr.Message,
|
||||
Resource: resource,
|
||||
RequestID: requestID,
|
||||
}
|
||||
|
||||
out, err := xml.MarshalIndent(payload, "", " ")
|
||||
|
||||
Reference in New Issue
Block a user