feat: complete OCI registry implementation with docker push/pull support

A lightweight OCI (Open Container Initiative) registry implementation written in Go.
This commit is contained in:
loveuer
2025-11-09 22:46:27 +08:00
commit 29088a6b54
45 changed files with 5629 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package middleware
import (
"github.com/gofiber/fiber/v3"
)
// CORS 跨域中间件
func CORS() fiber.Handler {
return func(c fiber.Ctx) error {
c.Set("Access-Control-Allow-Origin", "*")
c.Set("Access-Control-Allow-Credentials", "true")
c.Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE, PATCH, HEAD")
if c.Method() == "OPTIONS" {
return c.SendStatus(fiber.StatusNoContent)
}
return c.Next()
}
}

View File

@@ -0,0 +1,31 @@
package middleware
import (
"fmt"
"time"
"github.com/gofiber/fiber/v3"
)
// Logger 日志中间件
func Logger() fiber.Handler {
return func(c fiber.Ctx) error {
start := time.Now()
err := c.Next()
latency := time.Since(start)
fmt.Printf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
c.IP(),
time.Now().Format(time.RFC1123),
c.Method(),
c.Path(),
c.Protocol(),
c.Response().StatusCode(),
latency,
c.Get("User-Agent"),
"",
)
return err
}
}

View File

@@ -0,0 +1,24 @@
package middleware
import (
"github.com/gofiber/fiber/v3"
)
// Recovery 恢复中间件
func Recovery() fiber.Handler {
return func(c fiber.Ctx) error {
defer func() {
if r := recover(); r != nil {
c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"errors": []fiber.Map{
{
"code": "INTERNAL_ERROR",
"message": "Internal server error",
},
},
})
}
}()
return c.Next()
}
}

View File

@@ -0,0 +1,13 @@
package middleware
import (
"github.com/gofiber/fiber/v3"
)
// RepoMiddleware 仓库名中间件(如果需要的话)
func RepoMiddleware() fiber.Handler {
return func(c fiber.Ctx) error {
// 可以在这里处理仓库名相关的逻辑
return c.Next()
}
}