mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-12-02 00:38:46 +00:00
* refactor: Rename handler package to handlers in carrier-connector - Rename internal/handler directory to internal/handlers - Update handler import path in main.go and routes.go * feat: Add SM-DP+ handler with multi-carrier management and profile operations - Add SMDPHandler struct with manager field and NewSMDPHandler constructor - Add AddCarrier endpoint with JSON binding and carrier configuration support - Add RemoveCarrier endpoint with carrier ID parameter validation - Add DownloadProfile endpoint with 30-second timeout and context cancellation - Add GetCarrierStatus endpoint returning all carriers with timestamp - Add GetProfileStatus endpoint with EID/ICCID validation * feat: Add SM-DP+ integration layer with multi-carrier system initialization and route registration - Add SMDPIntegration struct with service, handler, repository, and logger fields - Add NewSMDPIntegration constructor with default carrier initialization - Add InitializeSystem method with carrier health logging and status tracking - Add RegisterRoutes method with profile, carrier, health, and metrics endpoints - Add healthHandler with carrier health status aggregation and degraded state detection - Add metricsHandler * feat: Add SM-DP+ service layer with multi-carrier management and profile download operations - Add SMDPService struct with manager, repository, and logger fields - Add NewSMDPService constructor with default config and background health checking - Add InitializeDefaultCarriers with AT&T, Verizon, and T-Mobile DE configurations - Add DownloadProfile method with context support and request logging - Add GetOptimalCarrier wrapping SelectCarrier for best carrier selection - Add GetCarrierHealth returning * feat: Add SM-DP+ manager with multi-carrier load balancing, health checking, and profile operations - Add DefaultManagerConfig with 30s health checks, 3 retries, and circuit breaker configuration - Add CarrierConfig struct with ES2 settings, MCC/MNC, priority, and feature support - Add ToCarrier method converting CarrierConfig to Carrier with metrics and capabilities - Add HealthChecker with periodic carrier health monitoring and status evaluation - Add LoadBalancer with weighted round-robin, least
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
// Package handlers hosts HTTP handlers for the carrier-connector service.
|
|
//
|
|
// Profile handlers (order, get, list, delete) live in profile_handlers.go and
|
|
// take a repository.ProfileRepository so profile state can be persisted and
|
|
// queried. Carrier-level handlers (info, connectivity) that only touch the
|
|
// ES2+ client live here.
|
|
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/es2"
|
|
)
|
|
|
|
// GetCarrierInfoHandler returns static carrier information from environment config.
|
|
func GetCarrierInfoHandler(_ *es2.ES2Client) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"carrier": gin.H{
|
|
"name": GetEnv("CARRIER_NAME", "Example Carrier"),
|
|
"mcc": GetEnv("CARRIER_MCC", "208"),
|
|
"mnc": GetEnv("CARRIER_MNC", "93"),
|
|
"smdpUrl": GetEnv("SMDP_URL", "https://smdp.example.com"),
|
|
"supported": true,
|
|
"lastChecked": time.Now().UTC(),
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// CheckConnectivityHandler probes the SM-DP+ via an ES2+ GetProfileStatus call
|
|
// with synthetic identifiers. A non-error response indicates the endpoint is
|
|
// reachable and accepting authenticated requests.
|
|
func CheckConnectivityHandler(client *es2.ES2Client) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
req := &es2.GetProfileStatusRequest{EID: "connectivity-probe", ICCID: "connectivity-probe"}
|
|
_, err := client.GetProfileStatus(context.Background(), req)
|
|
|
|
connected := err == nil
|
|
var errMsg any
|
|
if err != nil {
|
|
errMsg = err.Error()
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"connectivity": gin.H{
|
|
"smdpConnected": connected,
|
|
"checkedAt": time.Now().UTC(),
|
|
"error": errMsg,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
// parsePositiveInt parses a positive integer from a string, returning fallback on failure.
|
|
func parsePositiveInt(s string, fallback int) int {
|
|
if s == "" {
|
|
return fallback
|
|
}
|
|
n, err := strconv.Atoi(s)
|
|
if err != nil || n <= 0 {
|
|
return fallback
|
|
}
|
|
return n
|
|
}
|