Files
main-tbbank/backend/app.go
2026-08-04 18:01:20 +05:00

76 lines
1.9 KiB
Go
Executable File

package main
import (
_ "bankline/docs"
"bankline/internal/admin/auth"
"bankline/internal/config"
handlermanager "bankline/internal/handlers/manager"
"bankline/pkg/client/postgresql"
"bankline/pkg/logging"
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4/pgxpool"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Bank Service APIs
// @version 1.0
// @description Testing Swagger APIs.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:5050
// @BasePath /api/v1
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @tag.name auth
// @tag.name admin
// @tag.name categories
// @tag.name sub-categories
// @tag.name settings
// @Success 200 {object} appresult.AppSuccess "Success Code"
// @Failure 400 {object} appresult.AppError "Error Code"
// @schemes http
func main() {
cfg := config.GetConfig()
logger := logging.GetLogger()
postgresSQLClient := startPostgresql(cfg, logger)
start(handlermanager.Manager(postgresSQLClient, logger), cfg)
}
func startPostgresql(cfg *config.Config, logger *logging.Logger) *pgxpool.Pool {
postgresSQLClient, err := postgresql.NewClient(context.TODO(), 3, cfg.Storage)
if err != nil {
fmt.Println("error", err)
return nil
}
return postgresSQLClient
}
func start(router *gin.Engine, cfg *config.Config) {
logger := logging.GetLogger()
logger.Info("start application")
ginSwagger.WrapHandler(swaggerFiles.Handler,
ginSwagger.DefaultModelsExpandDepth(-1))
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.GET("/images/:id", auth.GetObject)
router.Run(`:` + cfg.Listen.Port)
}