Something went wrong. Try again.
An ATProto Powered Reputation Network
Something went wrong. Try again.
2.9 kB · 86 lines
Go
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687package main
import ( "log/slog" "os" "sync"
"provenance/internal/appview" "provenance/internal/atproto" "provenance/internal/config" "provenance/internal/domain" "provenance/internal/httpx" "provenance/internal/logging" "provenance/internal/microcosm" reputationalg "provenance/internal/reputation/algorithms" "provenance/internal/storage" "provenance/internal/telemetry" "provenance/internal/trust/algorithms" "provenance/internal/upstream")
func main() { if err := logging.Setup("appview"); err != nil { slog.Error("log configuration failed", "error", err) os.Exit(1) } if err := run(); err != nil { slog.Error("appview stopped", "error", err) os.Exit(1) }}
func run() error { ctx, cancel := httpx.Context() defer cancel() stopTrace, err := telemetry.Setup(ctx) if err != nil { return err } defer stopTrace() cfg, err := config.LoadAppview() if err != nil { return err } slog.Info("appview configuration loaded", "address", cfg.Address, "database", cfg.Database, "external_workers", cfg.ExternalWorkers, "soft_mode", cfg.SoftMode, "soft_vouches", cfg.SoftMode != domain.SoftDisabled, "soft_all_authors", domain.SoftAll(cfg.SoftMode), "soft_lists", domain.SoftLists(cfg.SoftMode), "replay", cfg.ReplayURL != "", "replay_origin", cfg.ReplayURL, "after_seq", cfg.ReplayRange.After, "before_seq", cfg.ReplayRange.Before, "trust_cache_ttl", cfg.TrustCacheTTL) openStore := storage.OpenWithSoft if cfg.ReplayURL != "" && cfg.ReplayRange.Before == 0 && domain.SoftAll(cfg.SoftMode) { openStore = storage.OpenForReplay } store, err := openStore(cfg.Database, cfg.SoftMode) if err != nil { return err } defer store.Close() slog.Info("database opened", "database", cfg.Database) queue, err := upstream.New(ctx, cfg.ExternalWorkers) if err != nil { return err } defer queue.Close() // This selection controls calculation, accepted query parameters, and the API schema. algorithm := algorithms.Optimistic{} phase := domain.IndexDisabled if cfg.ReplayURL != "" { phase = domain.IndexStarting } service := appview.NewWithOptions(store, atproto.NewRepositoryWithQueue(cfg.SoftMode, queue), cfg.Limits, appview.Options{Trust: algorithm, Reputation: reputationalg.DirectSum{}, CacheTTL: cfg.TrustCacheTTL, SoftMode: cfg.SoftMode, Indexing: phase}) var workers sync.WaitGroup if cfg.ReplayURL != "" { stream, err := microcosm.NewReplayWithRange(cfg.ReplayURL, cfg.ReplayKey, cfg.SoftMode, queue, cfg.ExternalWorkers, cfg.ReplayRange) if err != nil { return err } workers.Go(func() { service.RunReplay(ctx, stream) }) } else { stream, err := microcosm.NewWithQueue(cfg.JetstreamURL, cfg.SlingshotURL, cfg.SoftMode, queue) if err != nil { return err } workers.Go(func() { service.Run(ctx, stream) }) } err = httpx.Serve(ctx, cfg.Address, appview.Handler(service, cfg.ServiceKey)) cancel() workers.Wait() return err}