From 451403f8d178e66081ba23271741405ad1829a6d Mon Sep 17 00:00:00 2001 From: Savely Krendelhoff Date: Sat, 23 Aug 2025 16:06:16 +0700 Subject: [PATCH] [PHASE-8] Add config load --- cmd/server/main.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 055e4af..2283447 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -2,32 +2,48 @@ package main import ( "context" + "flag" "log/slog" + "net/http" "os" "os/signal" "syscall" "time" + "hash-of-wisdom/internal/config" "hash-of-wisdom/internal/lib/sl" "hash-of-wisdom/internal/pow/challenge" "hash-of-wisdom/internal/quotes" "hash-of-wisdom/internal/server" "hash-of-wisdom/internal/service" + + "github.com/prometheus/client_golang/prometheus/promhttp" + _ "net/http/pprof" ) func main() { - addr := ":8080" - if len(os.Args) > 1 { - addr = os.Args[1] + configPath := flag.String("config", "", "path to configuration file") + flag.Parse() + + // Load configuration + cfg, err := config.Load(*configPath) + if err != nil { + slog.Error("failed to load config", sl.Err(err)) + os.Exit(1) } logger := slog.Default() - logger.Info("starting word of wisdom server", "address", addr) + logger.Info("starting word of wisdom server", "address", cfg.Server.Address) - // Create components - challengeConfig, err := challenge.NewConfig() + // Create components using config + challengeConfig, err := challenge.NewConfig( + challenge.WithDefaultDifficulty(cfg.PoW.Difficulty), + challenge.WithMaxDifficulty(cfg.PoW.MaxDifficulty), + challenge.WithChallengeTTL(cfg.PoW.TTL), + challenge.WithHMACSecret([]byte(cfg.PoW.HMACSecret)), + ) if err != nil { - logger.Error("failed to create config", sl.Err(err)) + logger.Error("failed to create challenge config", sl.Err(err)) os.Exit(1) } generator := challenge.NewGenerator(challengeConfig)