Feat: finish object storage
This commit is contained in:
@@ -7,10 +7,13 @@ import (
|
||||
|
||||
"gitea.konchin.com/go2025/backend/handlers/api"
|
||||
"gitea.konchin.com/go2025/backend/handlers/auth"
|
||||
"gitea.konchin.com/go2025/backend/handlers/img"
|
||||
"gitea.konchin.com/go2025/backend/implements"
|
||||
"gitea.konchin.com/go2025/backend/middlewares"
|
||||
"gitea.konchin.com/go2025/backend/tracing"
|
||||
"gitea.konchin.com/go2025/backend/utils"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
@@ -57,39 +60,38 @@ var serveCmd = &cobra.Command{
|
||||
panic(err)
|
||||
}
|
||||
|
||||
/*
|
||||
// Initialize MinIO instance
|
||||
mc, err := minio.New(viper.GetString("minio-host"), &minio.Options{
|
||||
Creds: credentials.NewStaticV4(
|
||||
viper.GetString("minio-accesskey"),
|
||||
viper.GetString("minio-secretkey"),
|
||||
"",
|
||||
),
|
||||
Secure: viper.GetBool("minio-usessl"),
|
||||
})
|
||||
if err != nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error("failed to create minio client",
|
||||
zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
// Initialize MinIO instance
|
||||
mc, err := minio.New(viper.GetString("minio-host"), &minio.Options{
|
||||
Creds: credentials.NewStaticV4(
|
||||
viper.GetString("minio-accesskey"),
|
||||
viper.GetString("minio-secretkey"),
|
||||
"",
|
||||
),
|
||||
Secure: viper.GetBool("minio-usessl"),
|
||||
})
|
||||
if err != nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error("failed to create minio client",
|
||||
zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := utils.InitMinIO(ctx, mc); err != nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error("failed to minio init",
|
||||
zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
*/
|
||||
if err := utils.InitMinIO(ctx, mc); err != nil {
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Error("failed to minio init",
|
||||
zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Initialize custom interfaces
|
||||
db := implements.NewBunDatabase(bunDB)
|
||||
// s3 := implements.NewMinIOObjectStorage(mc)
|
||||
s3 := implements.NewMinIOObjectStorage(mc)
|
||||
|
||||
// Initialize handlers
|
||||
midHandlers := middlewares.NewHandlers(db)
|
||||
apis := api.NewHandlers(db)
|
||||
apis := api.NewHandlers(db, s3)
|
||||
auths := auth.NewHandlers(db)
|
||||
imgs := img.NewHandlers(s3)
|
||||
|
||||
// Initialize backend router
|
||||
router := bunrouter.New()
|
||||
@@ -103,12 +105,17 @@ var serveCmd = &cobra.Command{
|
||||
Use(midHandlers.CheckRefreshToken).
|
||||
Use(midHandlers.CheckAccessToken)
|
||||
apiGroup.GET("/images", apis.GetImages)
|
||||
apiGroup.GET("/aliases", apis.GetAliases)
|
||||
apiGroup.PUT("/image/:id/aliases", apis.PutImageAliases)
|
||||
|
||||
authGroup := backend.NewGroup("/auth")
|
||||
authGroup.POST("/login", auths.PostLogin)
|
||||
authGroup.POST("/gen-login-url",
|
||||
midHandlers.CheckPresharedKey(auths.PostGenLoginUrl))
|
||||
|
||||
imgGroup := backend.NewGroup("/img")
|
||||
imgGroup.GET("/:filename", imgs.Get)
|
||||
|
||||
if viper.GetBool("swagger") {
|
||||
backend.GET("/swagger/*any",
|
||||
bunrouter.HTTPHandlerFunc(
|
||||
|
||||
Reference in New Issue
Block a user