wip: oci image management

This commit is contained in:
loveuer
2025-11-09 15:19:11 +08:00
commit 8de8234372
58 changed files with 6142 additions and 0 deletions

102
internal/rerr/error.go Normal file
View File

@@ -0,0 +1,102 @@
package rerr
import (
"net/http"
"github.com/gofiber/fiber/v3"
)
// RepositoryError represents an error in the registry
type RepositoryError struct {
Status int `json:"status"`
Code string `json:"code"`
Message string `json:"message"`
}
func (e *RepositoryError) Error() string {
return e.Message
}
// Error responses
var (
ErrBlobUnknown = &RepositoryError{
Status: http.StatusNotFound,
Code: "BLOB_UNKNOWN",
Message: "blob unknown to registry",
}
ErrDigestInvalid = &RepositoryError{
Status: http.StatusBadRequest,
Code: "DIGEST_INVALID",
Message: "provided digest did not match uploaded content",
}
ErrDigestMismatch = &RepositoryError{
Status: http.StatusBadRequest,
Code: "DIGEST_MISMATCH",
Message: "provided digest did not match uploaded content",
}
ErrManifestUnknown = &RepositoryError{
Status: http.StatusNotFound,
Code: "MANIFEST_UNKNOWN",
Message: "manifest unknown",
}
ErrManifestInvalid = &RepositoryError{
Status: http.StatusBadRequest,
Code: "MANIFEST_INVALID",
Message: "manifest invalid",
}
ErrNameUnknown = &RepositoryError{
Status: http.StatusNotFound,
Code: "NAME_UNKNOWN",
Message: "repository name not known to registry",
}
ErrUnauthorized = &RepositoryError{
Status: http.StatusUnauthorized,
Code: "UNAUTHORIZED",
Message: "authentication required",
}
ErrDenied = &RepositoryError{
Status: http.StatusForbidden,
Code: "DENIED",
Message: "requested access to the resource is denied",
}
ErrUnsupported = &RepositoryError{
Status: http.StatusMethodNotAllowed,
Code: "UNSUPPORTED",
Message: "The operation is unsupported",
}
ErrTooManyRequests = &RepositoryError{
Status: http.StatusTooManyRequests,
Code: "TOOMANYREQUESTS",
Message: "too many requests",
}
)
// ErrInternal creates an internal server error
func ErrInternal(err error) *RepositoryError {
return &RepositoryError{
Status: http.StatusInternalServerError,
Code: "INTERNAL_SERVER_ERROR",
Message: err.Error(),
}
}
// Error sends a repository error response
func Error(c fiber.Ctx, err *RepositoryError) error {
return c.Status(err.Status).JSON(fiber.Map{
"errors": []fiber.Map{
{
"code": err.Code,
"message": err.Message,
},
},
})
}