owl-blogs/cmd/owl/main.go

85 lines
2.0 KiB
Go
Raw 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"
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{})
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)
siteConfigRepo := infra.NewConfigRepo(db)
2023-08-08 18:17:04 +00:00
interactionRepo := infra.NewInteractionRepo(db, interactionRegister)
2023-07-08 09:08:55 +00:00
// Create External Services
httpClient := &infra.OwlHttpClient{}
2023-08-09 19:56:56 +00:00
// busses
entryCreationBus := app.NewEntryCreationBus()
2023-08-08 18:17:04 +00:00
// Create Services
2023-08-09 19:56:56 +00:00
entryService := app.NewEntryService(entryRepo, entryCreationBus)
2023-07-08 09:08:55 +00:00
binaryService := app.NewBinaryFileService(binRepo)
2023-07-16 19:48:39 +00:00
authorService := app.NewAuthorService(authorRepo, siteConfigRepo)
2023-08-08 18:17:04 +00:00
webmentionService := app.NewWebmentionService(
interactionRepo, entryRepo, httpClient,
2023-08-08 18:17:04 +00:00
)
2023-07-08 11:28:06 +00:00
2023-08-10 19:56:06 +00:00
// plugins
plugings.NewEcho(entryCreationBus)
plugings.RegisterInstagram(
siteConfigRepo, configRegister, binaryService, entryCreationBus,
)
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-07-22 19:12:53 +00:00
authorService, siteConfigRepo, configRegister,
2023-08-09 18:36:44 +00:00
webmentionService, interactionRepo,
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
}