package main

import (
	"context"
	"log"
	"net/http"
	"time"
)

func main() {
	cfg, err := LoadConfig()
	if err != nil {
		log.Fatal(err)
	}

	sparql := NewAnzoGraphClient(cfg)
	if err := sparql.Startup(context.Background()); err != nil {
		log.Fatal(err)
	}

	api := &APIServer{
		cfg:       cfg,
		sparql:    sparql,
		snapshots: NewGraphSnapshotService(sparql, cfg),
	}

	srv := &http.Server{
		Addr:              cfg.ListenAddr,
		Handler:           api.handler(),
		ReadHeaderTimeout: 5 * time.Second,
	}

	log.Printf("backend listening on %s", cfg.ListenAddr)
	log.Fatal(srv.ListenAndServe())
}
