41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"time"
|
|
|
|
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/config"
|
|
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/database"
|
|
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/identity"
|
|
)
|
|
|
|
func main() {
|
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
logger.Error("configuration failed", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
if err := cfg.ValidateSeed(); err != nil {
|
|
logger.Error("seed configuration failed", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
pool, err := database.Open(ctx, cfg.DatabaseURL)
|
|
if err != nil {
|
|
logger.Error("database connection failed", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
defer pool.Close()
|
|
result, err := identity.SeedDemo(ctx, pool, cfg.DemoUsername, cfg.DemoPassword)
|
|
if err != nil {
|
|
logger.Error("demo account seed failed", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
logger.Info("demo account ready", "username", result.Username, "merchant_source_key", result.MerchantSourceKey,
|
|
"merchant_name", result.MerchantName, "password_source", "DEMO_PASSWORD")
|
|
}
|