package main import ( "context" "log" "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/jackc/pgx/v5/pgxpool" "github.com/lab/repo-integrations-core/internal/api" "github.com/lab/repo-integrations-core/internal/config" "github.com/lab/repo-integrations-core/internal/db" ) func main() { cfg := config.Load() pool, err := pgxpool.New(context.Background(), cfg.DatabaseURL) if err != nil { log.Fatalf("Unable to connect to database: %v\n", err) } defer pool.Close() queries := db.New(pool) apiHandler := api.New(cfg, queries) r := chi.NewRouter() r.Use(middleware.Logger) r.Use(middleware.Recoverer) r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Repo Integrations Core")) }) r.Route("/integrations/github", func(r chi.Router) { r.Get("/connect", apiHandler.ConnectGithubHandler) r.Get("/callback", apiHandler.ConnectGithubCallbackHandler) }) r.Post("/webhooks/github", apiHandler.GithubWebhookHandler) r.Get("/repositories", apiHandler.ListRepositoriesHandler) log.Println("Starting server on :8080") if err := http.ListenAndServe(":8080", r); err != nil { log.Fatalf("Could not start server: %s\n", err) } }