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:
21
internal/middleware/cors.go
Normal file
21
internal/middleware/cors.go
Normal 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()
|
||||
}
|
||||
}
|
||||
31
internal/middleware/logger.go
Normal file
31
internal/middleware/logger.go
Normal 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
|
||||
}
|
||||
}
|
||||
24
internal/middleware/recovery.go
Normal file
24
internal/middleware/recovery.go
Normal 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()
|
||||
}
|
||||
}
|
||||
13
internal/middleware/repo.go
Normal file
13
internal/middleware/repo.go
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user