Files
online-backend/app.go
2026-07-16 17:53:45 +05:00

76 lines
2.0 KiB
Go
Executable File

package main
import (
"context"
"online-back/docs"
"online-back/internal/config"
handlermanager "online-back/internal/handlers/manager"
"online-back/pkg/client/postgresql"
"online-back/pkg/logging"
"github.com/jackc/pgx/v4/pgxpool"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Service APIs
// @version 1.0
// @description Online payment system admin API.
// @host localhost:5050
// @BasePath /api/admin
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @schemes http
// @tag.name auth
// @tag.description Authentication
// @tag.name province
// @tag.description Provinces
// @tag.name branches
// @tag.description Branches
// @tag.name payment-card
// @tag.description Payment cards
// @tag.name reason-card
// @tag.description Reason cards
// @tag.name loan-type
// @tag.description Loan types
// @tag.name loan-document
// @tag.description Loan required documents
// @tag.name loans-repayment
// @tag.description Loan repayments
// @tag.name card-orders
// @tag.description Card orders
// @tag.name activity-logs
// @tag.description User activity audit trail
func main() {
docs.SwaggerInfo.Title = "Service APIs"
docs.SwaggerInfo.Version = "1.0"
docs.SwaggerInfo.Description = "Online payment system admin API."
docs.SwaggerInfo.Host = "localhost:5050"
docs.SwaggerInfo.BasePath = "/api/admin"
docs.SwaggerInfo.Schemes = []string{"http"}
cfg := config.GetConfig()
logger := logging.GetLogger()
pool := mustConnectPostgresql(cfg, logger)
router := handlermanager.New(cfg, pool, logger)
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
addr := cfg.Listen.BindIP + ":" + cfg.Listen.Port
logger.Infof("starting server on %s", addr)
if err := router.Run(addr); err != nil {
logger.Fatal(err)
}
}
func mustConnectPostgresql(cfg *config.Config, logger *logging.Logger) *pgxpool.Pool {
pool, err := postgresql.NewClient(context.Background(), 3, cfg.Storage)
if err != nil {
logger.Fatal(err)
}
return pool
}