website-feeds

Make RSS feeds of your favorite "vote on posts" websites

git clone https://code.pdelong.com/website-feeds.git

 1package main
 2
 3import (
 4	"context"
 5	"log/slog"
 6	"os"
 7	"os/signal"
 8	"syscall"
 9
10	"website-feeds/server"
11	"website-feeds/store"
12)
13
14func run() int {
15	databaseURL := os.Getenv("WEBSITE_FEEDS_DATABASE_URL")
16	configError := false
17	if databaseURL == "" {
18		slog.Error("WEBSITE_FEEDS_DATABASE_URL was empty")
19		configError = true
20	}
21
22	bindAddr := os.Getenv("WEBSITE_FEEDS_BIND_ADDR")
23	if bindAddr == "" {
24		slog.Error("WEBSITE_FEEDS_BIND_ADDR was empty")
25		configError = true
26	}
27
28	if configError {
29		slog.Error("Failed to read configuration. See logs for details")
30		return 1
31	}
32
33	ctx := context.Background()
34	ctx, stop := signal.NotifyContext(
35		ctx,
36		syscall.SIGINT,
37		syscall.SIGTERM,
38		syscall.SIGQUIT,
39	)
40	defer stop()
41
42	slog.Info("Connecting to store")
43	s, err := store.NewPostgres(ctx, databaseURL)
44	if err != nil {
45		slog.Error(
46			"Failed to connect to store",
47			slog.Any("err", err),
48		)
49		return 1
50	}
51	defer s.Close()
52
53	server.Run(ctx, stop, s, bindAddr)
54
55	return 0
56}
57
58func main() {
59	os.Exit(run())
60}