From 5b8c5d81d5dc9c51920d99b122908c5e92af8183 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Tue, 14 Apr 2026 15:50:08 +0300 Subject: [PATCH] feat: Add configuration management for api-server - Add Config struct with server, database, Redis, IMSI, and ES2+ settings - Add ServerConfig with port and timeout settings (30s read/write) - Add DatabaseConfig for PostgreSQL connection parameters - Add RedisConfig for cache connection settings - Add IMSIConfig with France MCC+MNC prefix (20893) and IMSI range - Add ES2Config for eSIM provisioning with SMDP connection parameters - Add LoadConfig function with default configuration values - Include JSON --- apps/api-server/internal/config/config.go | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 apps/api-server/internal/config/config.go diff --git a/apps/api-server/internal/config/config.go b/apps/api-server/internal/config/config.go new file mode 100644 index 0000000..10d412d --- /dev/null +++ b/apps/api-server/internal/config/config.go @@ -0,0 +1,83 @@ +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"` +} + +type ServerConfig struct { + Port string `json:"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 ES2Config struct { + BaseURL string `json:"base_url"` + APIKey string `json:"api_key"` + InsecureSkipVerify bool `json:"insecure_skip_verify"` + FunctionalityRequesterID string `json:"functionality_requester_id"` +} + +func LoadConfig() *Config { + return &Config{ + Server: ServerConfig{ + Port: "8000", + 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", + }, + } +}