Files
telecom-platform/apps/api-server/internal/config/config.go
T
nutcas3 d7e83c1f0d feat: Add API key authentication support to charging engine client
- Add APIKey field to ChargingEngineConfig struct
- Add apiKey field to ChargingEngineClient struct
- Add setAPIKeyHeader method to set X-API-Key header when API key is configured
- Call setAPIKeyHeader in CheckCredit, DeductCredit, AddCredit, GetBalance, and HealthCheck methods
2026-04-25 03:43:32 +03:00

131 lines
3.2 KiB
Go

package config
import (
"time"
)
type Config struct {
Server ServerConfig `json:"server"`
Database DatabaseConfig `json:"database"`
Redis RedisConfig `json:"redis"`
IMSI IMSIConfig `json:"imsi"`
ES2 ES2Config `json:"es2"`
Payment PaymentConfig `json:"payment"`
ChargingEngine ChargingEngineConfig `json:"charging_engine"`
InfluxDB InfluxDBConfig `json:"influxdb"`
Auth AuthConfig `json:"auth"`
}
type ChargingEngineConfig struct {
BaseURL string `json:"base_url"`
Timeout time.Duration `json:"timeout"`
APIKey string `json:"api_key"`
}
type PaymentConfig struct {
Provider string `json:"provider"`
StripeAPIKey string `json:"stripe_api_key"`
StripeWebhookSecret string `json:"stripe_webhook_secret"`
}
type ServerConfig struct {
Port string `json:"port"`
MetricsPort string `json:"metrics_port"`
ReadTimeout time.Duration `json:"read_timeout"`
WriteTimeout time.Duration `json:"write_timeout"`
}
type DatabaseConfig struct {
Host string `json:"host"`
Port string `json:"port"`
Database string `json:"database"`
Username string `json:"username"`
Password string `json:"password"`
SSLMode string `json:"ssl_mode"`
}
type RedisConfig struct {
Host string `json:"host"`
Port string `json:"port"`
Password string `json:"password"`
DB int `json:"db"`
}
type IMSIConfig struct {
Prefix string `json:"prefix"`
MinIMSI uint64 `json:"min_imsi"`
MaxIMSI uint64 `json:"max_imsi"`
}
type InfluxDBConfig struct {
URL string `json:"url"`
Token string `json:"token"`
Org string `json:"org"`
Bucket string `json:"bucket"`
}
type ES2Config struct {
BaseURL string `json:"base_url"`
APIKey string `json:"api_key"`
InsecureSkipVerify bool `json:"insecure_skip_verify"`
FunctionalityRequesterID string `json:"functionality_requester_id"`
}
type AuthConfig struct {
JWTSecret string `json:"jwt_secret"`
}
func LoadConfig() *Config {
return &Config{
Server: ServerConfig{
Port: "8000",
MetricsPort: "9090",
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
},
Database: DatabaseConfig{
Host: "localhost",
Port: "5432",
Database: "telecom_platform",
Username: "postgres",
Password: "password",
SSLMode: "disable",
},
Redis: RedisConfig{
Host: "localhost",
Port: "6379",
Password: "",
DB: 0,
},
IMSI: IMSIConfig{
Prefix: "20893", // France MCC+MNC
MinIMSI: 1,
MaxIMSI: 999999999,
},
ES2: ES2Config{
BaseURL: "https://smdp.example.com",
APIKey: "",
InsecureSkipVerify: true,
FunctionalityRequesterID: "telecom-platform",
},
Payment: PaymentConfig{
Provider: "stripe",
StripeAPIKey: "",
StripeWebhookSecret: "",
},
ChargingEngine: ChargingEngineConfig{
BaseURL: "http://localhost:3001",
Timeout: 10 * time.Second,
},
InfluxDB: InfluxDBConfig{
URL: "http://localhost:8086",
Token: "",
Org: "telecom",
Bucket: "telecom",
},
Auth: AuthConfig{
JWTSecret: "change-me-in-production",
},
}
}