Feat: add session

This commit is contained in:
2025-12-07 11:27:54 +08:00
parent 9c30bc009d
commit fb1c47b321
12 changed files with 400 additions and 12 deletions

View File

@@ -1,15 +1,21 @@
package cmds
import (
"database/sql"
"log"
"net/http"
"gitea.konchin.com/go2025/backend/handlers/api"
"gitea.konchin.com/go2025/backend/implements"
"gitea.konchin.com/go2025/backend/middlewares"
"gitea.konchin.com/go2025/backend/tracing"
"github.com/spf13/cobra"
"github.com/spf13/viper"
httpSwagger "github.com/swaggo/http-swagger"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
"github.com/uptrace/bun/extra/bunotel"
"github.com/uptrace/bunrouter"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
@@ -35,13 +41,13 @@ var serveCmd = &cobra.Command{
defer tracing.DeferUptrace(ctx)
}
/*
// Initialize DB instance
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(
viper.GetString("pg-connection-string"))))
bunDB := bun.NewDB(sqldb, pgdialect.New())
bunDB.AddQueryHook(bunotel.NewQueryHook(bunotel.WithDBName("backend")))
// Initialize DB instance
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(
viper.GetString("pg-connection-string"))))
bunDB := bun.NewDB(sqldb, pgdialect.New())
bunDB.AddQueryHook(bunotel.NewQueryHook(bunotel.WithDBName("backend")))
/*
// Initialize MinIO instance
mc, err := minio.New(viper.GetString("minio-host"), &minio.Options{
Creds: credentials.NewStaticV4(
@@ -64,15 +70,15 @@ var serveCmd = &cobra.Command{
zap.Error(err))
panic(err)
}
// Initialize custom interfaces
db := implements.NewBunDatabase(bunDB)
s3 := implements.NewMinIOObjectStorage(mc)
*/
// Initialize custom interfaces
db := implements.NewBunDatabase(bunDB)
// s3 := implements.NewMinIOObjectStorage(mc)
// Initialize handlers
apis := api.NewHandlers()
midHandlers := middlewares.NewHandlers(db)
// Initialize backend router
router := bunrouter.New()
@@ -82,7 +88,9 @@ var serveCmd = &cobra.Command{
Use(middlewares.AccessLog).
Use(middlewares.CORSHandler)
apiGroup := backend.NewGroup("/api")
apiGroup := backend.NewGroup("/api").
Use(midHandlers.CheckRefreshToken).
Use(midHandlers.CheckAccessToken)
apiGroup.GET("/images", apis.GetImages)
if viper.GetBool("swagger") {