Files
online-backend/app.go
2026-07-04 18:34:30 +05:00

67 lines
1.8 KiB
Go
Executable File

package main
import (
"context"
_ "online-back/docs"
"online-back/internal/admin/auth"
"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.
// @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 /v1/admin
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @tag.name auth
// @tag.name province
// @tag.name location
// @tag.name branches
// @tag.name payment-card
// @tag.name reason-card
// @tag.name loan-type
// @tag.name loan-document
// @Success 200 {object} appresult.AppSuccess "Success Code"
// @Failure 400 {object} appresult.AppError "Error Code"
// @schemes http
func main() {
cfg := config.GetConfig()
logger := logging.GetLogger()
pool := mustConnectPostgresql(cfg, logger)
router := handlermanager.New(cfg, pool, logger)
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.GET("/images/:id", auth.GetObject)
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
}