owl-blogs/cmd/owl/main.go

99 lines
2.5 KiB
Go
Raw Permalink Normal View History

2023-06-25 18:04:06 +00:00
package main
import (
2023-07-08 12:28:15 +00:00
"fmt"
"os"
2023-06-25 19:32:36 +00:00
"owl-blogs/app"
2023-07-16 19:48:39 +00:00
entrytypes "owl-blogs/entry_types"
2023-06-25 19:32:36 +00:00
"owl-blogs/infra"
2023-08-08 18:17:04 +00:00
"owl-blogs/interactions"
2023-08-09 19:56:56 +00:00
"owl-blogs/plugings"
"owl-blogs/render"
2023-06-25 19:32:36 +00:00
"owl-blogs/web"
2023-07-08 12:28:15 +00:00
"github.com/spf13/cobra"
2023-06-25 18:04:06 +00:00
)
2023-07-07 19:04:25 +00:00
const DbPath = "owlblogs.db"
2023-07-08 12:28:15 +00:00
var rootCmd = &cobra.Command{
Use: "owl",
Short: "Owl Blogs is a not so static blog generator",
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
2023-07-07 19:04:25 +00:00
func App(db infra.Database) *web.WebApp {
2023-08-08 18:17:04 +00:00
// Register Types
entryRegister := app.NewEntryTypeRegistry()
entryRegister.Register(&entrytypes.Image{})
entryRegister.Register(&entrytypes.Article{})
entryRegister.Register(&entrytypes.Page{})
entryRegister.Register(&entrytypes.Recipe{})
entryRegister.Register(&entrytypes.Note{})
entryRegister.Register(&entrytypes.Bookmark{})
entryRegister.Register(&entrytypes.Reply{})
interactionRegister := app.NewInteractionTypeRegistry()
interactionRegister.Register(&interactions.Webmention{})
2024-05-17 20:37:18 +00:00
interactionRegister.Register(&interactions.Like{})
interactionRegister.Register(&interactions.Repost{})
2023-08-08 18:17:04 +00:00
configRegister := app.NewConfigRegister()
// Create Repositories
entryRepo := infra.NewEntryRepository(db, entryRegister)
2023-07-08 09:08:55 +00:00
binRepo := infra.NewBinaryFileRepo(db)
2023-07-08 11:28:06 +00:00
authorRepo := infra.NewDefaultAuthorRepo(db)
2023-08-11 14:11:59 +00:00
configRepo := infra.NewConfigRepo(db)
2023-08-08 18:17:04 +00:00
interactionRepo := infra.NewInteractionRepo(db, interactionRegister)
2024-05-13 17:03:21 +00:00
followersRepo := infra.NewFollowerRepository(db)
2023-07-08 09:08:55 +00:00
// Create External Services
httpClient := &infra.OwlHttpClient{}
2023-08-09 19:56:56 +00:00
// busses
eventBus := app.NewEventBus()
2023-08-09 19:56:56 +00:00
2023-08-08 18:17:04 +00:00
// Create Services
siteConfigService := app.NewSiteConfigService(configRepo)
2024-05-17 20:37:18 +00:00
entryService := app.NewEntryService(entryRepo, siteConfigService, eventBus)
2023-07-08 09:08:55 +00:00
binaryService := app.NewBinaryFileService(binRepo)
authorService := app.NewAuthorService(authorRepo, siteConfigService)
2023-08-08 18:17:04 +00:00
webmentionService := app.NewWebmentionService(
siteConfigService, interactionRepo, entryRepo, httpClient, eventBus,
2023-08-08 18:17:04 +00:00
)
2024-05-17 20:37:18 +00:00
apService := app.NewActivityPubService(
followersRepo, configRepo, interactionRepo,
2024-05-18 14:12:35 +00:00
entryService, siteConfigService, binaryService,
2024-05-17 20:37:18 +00:00
eventBus,
)
2023-07-08 11:28:06 +00:00
// setup render functions
render.SiteConfigService = siteConfigService
2023-08-10 19:56:06 +00:00
// plugins
plugings.NewEcho(eventBus)
2023-08-10 19:56:06 +00:00
plugings.RegisterInstagram(
2023-08-11 14:11:59 +00:00
configRepo, configRegister, binaryService, eventBus,
2023-08-10 19:56:06 +00:00
)
2023-08-08 18:17:04 +00:00
// Create WebApp
2023-07-22 19:12:53 +00:00
return web.NewWebApp(
2023-08-08 18:17:04 +00:00
entryService, entryRegister, binaryService,
2023-08-11 14:11:59 +00:00
authorService, configRepo, configRegister,
siteConfigService, webmentionService, interactionRepo,
2024-05-13 17:03:21 +00:00
apService,
2023-07-22 19:12:53 +00:00
)
2023-07-06 20:16:52 +00:00
}
func main() {
2023-07-08 12:28:15 +00:00
Execute()
2023-06-25 18:04:06 +00:00
}