Files
telecom-platform/apps/carrier-connector/main.go
T
nutcas3 24586bbeb4 feat: Refactor carrier-connector main.go to extract route setup and handlers into separate packages for improved modularity
- Move setupRoutes to routes.go with ProfileRepository parameter and handler package integration
- Extract all handler functions (orderProfile/getProfile/listProfiles/deleteProfile/getCarrierInfo/checkConnectivity) to internal/handler package
- Move ProfileOrder/ProfileResponse structs to internal/handler package as shared types
- Move getEnv helper function to handler.Get
2026-04-24 08:50:41 +03:00

53 lines
1.7 KiB
Go

package main
import (
"fmt"
"os"
"time"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/config"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
handler "github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/handler"
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/repository"
"github.com/rs/zerolog"
)
func main() {
handler.Logger = zerolog.New(os.Stdout).With().
Timestamp().
Str("service", "carrier-connector").
Logger()
if err := godotenv.Load(); err != nil {
handler.Logger.Info().Msg("No .env file found, using system environment")
}
client := es2.NewES2Client(&config.ES2Config{
BaseURL: handler.GetEnv("SMDP_URL", "https://smdp.example.com"),
APIKey: handler.GetEnv("SMDP_API_KEY", "test-api-key"),
FunctionalityRequesterID: handler.GetEnv("FUNCTIONALITY_REQUESTER_ID", "carrier-connector"),
InsecureSkipVerify: handler.GetEnv("INSECURE_SKIP_VERIFY", "true") == "true",
})
port := handler.GetEnv("PORT", "8080")
router := gin.Default()
router.Use(gin.LoggerWithFormatter(func(p gin.LogFormatterParams) string {
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
p.ClientIP, p.TimeStamp.Format(time.RFC1123),
p.Method, p.Path, p.Request.Proto,
p.StatusCode, p.Latency, p.Request.UserAgent(), p.ErrorMessage,
)
}))
router.Use(gin.Recovery())
profileRepo := repository.NewInMemoryProfileStore()
setupRoutes(router, client, profileRepo)
handler.Logger.Info().Str("port", port).Msg("Carrier Connector API server starting")
if err := router.Run(":" + port); err != nil {
handler.Logger.Fatal().Err(err).Msg("Failed to start server")
}
}