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 (
"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)