Feat: add session
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user