You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.0 KiB
115 lines
3.0 KiB
package main |
|
|
|
import ( |
|
"context" |
|
"flag" |
|
"time" |
|
|
|
"gitcitadel-online/internal/cache" |
|
"gitcitadel-online/internal/config" |
|
"gitcitadel-online/internal/generator" |
|
"gitcitadel-online/internal/logger" |
|
"gitcitadel-online/internal/nostr" |
|
"gitcitadel-online/internal/server" |
|
) |
|
|
|
func main() { |
|
configPath := flag.String("config", "config.yaml", "Path to configuration file") |
|
devMode := flag.Bool("dev", false, "Enable development mode") |
|
logLevel := flag.String("log-level", "info", "Log level (debug, info, warn, error)") |
|
flag.Parse() |
|
|
|
// Initialize logger |
|
if *devMode { |
|
logger.Init("debug", true) |
|
} else { |
|
logger.Init(*logLevel, false) |
|
} |
|
|
|
// Load configuration |
|
cfg, err := config.LoadConfig(*configPath) |
|
if err != nil { |
|
logger.Fatalf("Failed to load config: %v", err) |
|
} |
|
|
|
if err := cfg.Validate(); err != nil { |
|
logger.Fatalf("Invalid config: %v", err) |
|
} |
|
|
|
if *devMode { |
|
logger.Info("Development mode enabled") |
|
} |
|
|
|
// Initialize caches |
|
pageCache := cache.NewCache() |
|
feedCache := cache.NewFeedCache() |
|
|
|
// Initialize Nostr client |
|
nostrClient := nostr.NewClient(cfg.Relays.Primary, cfg.Relays.Fallback, cfg.Relays.AdditionalFallback) |
|
ctx := context.Background() |
|
if err := nostrClient.Connect(ctx); err != nil { |
|
logger.Warnf("Failed to connect to relays: %v", err) |
|
} |
|
|
|
// Initialize services |
|
// Use standard Nostr kind constants |
|
articleKinds := nostr.SupportedArticleKinds() |
|
wikiService := nostr.NewWikiService(nostrClient, articleKinds, nostr.KindWiki, cfg.Relays.AdditionalFallback, nostr.KindIndex, nostr.KindBlog, nostr.KindLongform) |
|
feedService := nostr.NewFeedService(nostrClient, nostr.KindNote) |
|
issueService := nostr.NewIssueService(nostrClient, nostr.KindIssue, nostr.KindRepoAnnouncement) |
|
ebooksService := nostr.NewEBooksService(nostrClient, nostr.KindIndex, "wss://theforest.nostr1.com") |
|
|
|
// Initialize HTML generator |
|
htmlGenerator, err := generator.NewHTMLGenerator( |
|
"templates", |
|
cfg.LinkBaseURL, |
|
cfg.SEO.SiteName, |
|
cfg.SEO.SiteURL, |
|
cfg.SEO.DefaultImage, |
|
nostrClient, |
|
) |
|
if err != nil { |
|
logger.Fatalf("Failed to initialize HTML generator: %v", err) |
|
} |
|
|
|
// Initialize cache rewarming |
|
rewarmer := cache.NewRewarmer( |
|
pageCache, |
|
feedCache, |
|
wikiService, |
|
feedService, |
|
ebooksService, |
|
htmlGenerator, |
|
cfg.WikiIndex, |
|
cfg.BlogIndex, |
|
cfg.Feed.Relay, |
|
cfg.Feed.MaxEvents, |
|
time.Duration(cfg.Cache.RefreshIntervalMinutes)*time.Minute, |
|
time.Duration(cfg.Feed.PollIntervalMinutes)*time.Minute, |
|
) |
|
|
|
// Start cache rewarming |
|
rewarmer.Start(ctx) |
|
|
|
// Initialize HTTP server |
|
httpServer := server.NewServer(cfg.Server.Port, pageCache, feedCache, issueService, cfg.RepoAnnouncement, htmlGenerator, nostrClient) |
|
|
|
// Start server in goroutine |
|
go func() { |
|
if err := httpServer.Start(); err != nil { |
|
logger.Fatalf("Server failed: %v", err) |
|
} |
|
}() |
|
|
|
logger.Infof("Server started on port %d", cfg.Server.Port) |
|
logger.Info("Waiting for initial cache population...") |
|
|
|
// Wait a bit for initial cache |
|
time.Sleep(5 * time.Second) |
|
|
|
// Wait for shutdown signal |
|
httpServer.WaitForShutdown() |
|
|
|
// Close Nostr client |
|
nostrClient.Close() |
|
}
|
|
|