[PHASE-8] Add config load

This commit is contained in:
Savely Krendelhoff 2025-08-23 16:06:16 +07:00
parent 0bf84576a8
commit 451403f8d1
No known key found for this signature in database
GPG key ID: F70DFD34F40238DE

View file

@ -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)