Cast AID Agent 60785a52f5 Add SMS API load testing service for Cast
Go service that load tests the Cast SMS/OTP API with configurable
concurrent threads, target RPS, ramp-up period, and message parts.
Features live stats, final report with SMS parts tracking, and
config warnings for suboptimal test parameters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 10:19:20 +01:00

60 lines
1.2 KiB
Go

package config
import (
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
type Config struct {
APIURL string
APIKey string
SenderID string
Recipient string
MsgParts int
Threads int
RPS int
DurationSec int
RampUpSec int
}
func Load() Config {
if err := godotenv.Load(); err != nil {
log.Println("Warning: .env file not found, using environment variables")
}
return Config{
APIURL: mustEnv("SMS_API_URL"),
APIKey: mustEnv("SMS_API_KEY"),
SenderID: mustEnv("SMS_SENDER_ID"),
Recipient: mustEnv("SMS_RECIPIENT"),
MsgParts: envInt("SMS_MESSAGE_PARTS", 1),
Threads: envInt("LOAD_TEST_THREADS", 10),
RPS: envInt("LOAD_TEST_RPS", 50),
DurationSec: envInt("LOAD_TEST_DURATION_SECS", 30),
RampUpSec: envInt("LOAD_TEST_RAMP_UP_SECS", 5),
}
}
func mustEnv(key string) string {
val := os.Getenv(key)
if val == "" {
log.Fatalf("Required environment variable %s is not set", key)
}
return val
}
func envInt(key string, defaultVal int) int {
val := os.Getenv(key)
if val == "" {
return defaultVal
}
n, err := strconv.Atoi(val)
if err != nil {
log.Fatalf("Invalid integer for %s: %s", key, val)
}
return n
}