PHASE-8: Instrumenting #9

Merged
krendelhoff merged 10 commits from phase-8-instrumenting into master 2025-08-23 13:54:08 +03:00
Showing only changes of commit 451403f8d1 - Show all commits

View file

@ -2,32 +2,48 @@ package main
import ( import (
"context" "context"
"flag"
"log/slog" "log/slog"
"net/http"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time" "time"
"hash-of-wisdom/internal/config"
"hash-of-wisdom/internal/lib/sl" "hash-of-wisdom/internal/lib/sl"
"hash-of-wisdom/internal/pow/challenge" "hash-of-wisdom/internal/pow/challenge"
"hash-of-wisdom/internal/quotes" "hash-of-wisdom/internal/quotes"
"hash-of-wisdom/internal/server" "hash-of-wisdom/internal/server"
"hash-of-wisdom/internal/service" "hash-of-wisdom/internal/service"
"github.com/prometheus/client_golang/prometheus/promhttp"
_ "net/http/pprof"
) )
func main() { func main() {
addr := ":8080" configPath := flag.String("config", "", "path to configuration file")
if len(os.Args) > 1 { flag.Parse()
addr = os.Args[1]
// 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 := slog.Default()
logger.Info("starting word of wisdom server", "address", addr) logger.Info("starting word of wisdom server", "address", cfg.Server.Address)
// Create components // Create components using config
challengeConfig, err := challenge.NewConfig() 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 { 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) os.Exit(1)
} }
generator := challenge.NewGenerator(challengeConfig) generator := challenge.NewGenerator(challengeConfig)