package main import ( "fmt" "log/slog" "net/http" "os" "git.leonardobishop.net/stash/api" "git.leonardobishop.net/stash/internal/config" "git.leonardobishop.net/stash/internal/constants" "git.leonardobishop.net/stash/pkg/database" "git.leonardobishop.net/stash/pkg/entries" "git.leonardobishop.net/stash/pkg/html" "git.leonardobishop.net/stash/pkg/kinds" ) 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(constants.SysConfPrefix+"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) kindsService := kinds.NewService(db) htmlService := html.NewService() api := api.NewServer(api.ApiServices{ EntiresService: entriesService, KindsService: kindsService, HtmlService: htmlService, Config: c, }) 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 }