Files
tm_back/cmd/web/main.go
T
n.nakhostin 9119e2383e Add configuration file and update server settings
- Introduced a new `config.yaml` file for managing server, database, cache, queue, AI, scraping, logging, and rate limiting configurations.
- Updated `docker-compose.yml` to reflect the new server port (8081) and adjusted health check endpoints accordingly.
- Modified `Dockerfile` to expose the new server port.
- Updated `README.md` to reflect changes in server configuration and added documentation for the new configuration structure.
- Added test scripts for server and Swagger documentation testing.
- Refactored customer domain structure to align with new configuration settings and improve maintainability.
2025-08-02 12:37:04 +03:30

128 lines
3.1 KiB
Go

// Package main Tender Management API
//
// This is the API documentation for the Tender Management System.
//
// Schemes: http, https
// Host: localhost:8081
// BasePath: /api/v1
// Version: 1.0.0
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// - bearer
//
// swagger:meta
package main
// @title Tender Management API
// @version 1.0.0
// @description This is the API documentation for the Tender Management System.
// @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:8081
// @BasePath /api/v1
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @description Type "Bearer" followed by a space and JWT token.
// @tag.name customers
// @tag.description Customer management operations
// @tag.name health
// @tag.description Health check operations
// @tag.name auth
// @tag.description Authentication operations
import (
"context"
"fmt"
"net/http"
"time"
"tm/internal/customer"
_ "tm/cmd/web/docs" // This is generated by swag
)
func main() {
conf := initConfig()
logger := initLogger(conf.Logging)
defer logger.Sync()
// Initialize MongoDB connection manager
mongoManager := initMongoDB(conf.Database.MongoDB, logger)
defer func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := mongoManager.Close(ctx); err != nil {
logger.Error("Failed to close MongoDB connection", map[string]interface{}{
"error": err.Error(),
})
}
}()
logger.Info(
"Starting Tender Management API Server",
map[string]interface{}{
"version": "1.0.0",
"host": conf.Server.Host,
"port": conf.Server.Port,
})
// Initialize repositories with MongoDB connection manager
customerRepository := customer.NewCustomerRepository(mongoManager, logger)
logger.Info("Repositories initialized successfully", map[string]interface{}{
"repositories": []string{"customer"},
})
// Initialize services with repositories
customerService := customer.NewCustomerService(customerRepository, logger)
logger.Info("Services initialized successfully", map[string]interface{}{
"services": []string{"customer"},
})
// Initialize handlers with services
customerHandler := customer.NewHandler(customerService)
logger.Info("Handlers initialized successfully", map[string]interface{}{
"handlers": []string{"customer"},
})
// Initialize HTTP server
e := initHTTPServer(conf, logger)
// Register routes
customerHandler.RegisterRoutes(e)
// Start server
serverAddr := fmt.Sprintf("%s:%d", conf.Server.Host, conf.Server.Port)
logger.Info("HTTP server starting", map[string]interface{}{
"address": serverAddr,
})
if err := e.Start(serverAddr); err != nil && err != http.ErrServerClosed {
logger.Error("Failed to start HTTP server", map[string]interface{}{
"error": err.Error(),
"address": serverAddr,
})
panic(fmt.Sprintf("Failed to start HTTP server: %v", err))
}
}