summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-09-09 22:44:09 +0100
committerLeonardo Bishop <me@leonardobishop.net>2025-09-09 22:44:09 +0100
commitf1741a7faa9538e9b12ac60e0fbf6c7721a36059 (patch)
tree2b70b14fc20a8520718910a0cd2e0134790c6f53 /main.go
Initial commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..e337b0e
--- /dev/null
+++ b/main.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+ "fmt"
+ "log/slog"
+ "net/http"
+ "os"
+
+ "git.leonardobishop.net/history/api"
+ "git.leonardobishop.net/history/internal/config"
+ "git.leonardobishop.net/history/pkg/database"
+ "git.leonardobishop.net/history/pkg/entries"
+ "git.leonardobishop.net/history/pkg/html"
+)
+
+func main() {
+ if err := run(); err != nil {
+ slog.Error("Unhandled error", "error", err)
+ os.Exit(1)
+ }
+}
+
+func run() error {
+ c := &config.Config{}
+ err := config.ReadConfig("config.yaml", c)
+ if err != nil {
+ return fmt.Errorf("failed to load config: %w", err)
+ }
+
+ db, err := database.Connect("database.db")
+ if err != nil {
+ return fmt.Errorf("failed to connect to database: %w", err)
+ }
+
+ if err := database.Migrate(db); err != nil {
+ return fmt.Errorf("database migration failed: %w", err)
+ }
+
+ entriesService := entries.NewService(db)
+ htmlService := html.NewService()
+
+ api := api.NewServer(api.ApiServices{
+ EntiresService: entriesService,
+ HtmlService: htmlService,
+ })
+
+ slog.Info("starting HTTP server", "host", c.Server.Host, "port", c.Server.Port)
+
+ if err := http.ListenAndServe(fmt.Sprintf("%s:%s", c.Server.Host, c.Server.Port), api); err != nil {
+ return fmt.Errorf("failed to start server: %w", err)
+ }
+
+ return nil
+}