owl-blogs/cmd/owl/main.go

54 lines
1.1 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-08 11:28:06 +00:00
"owl-blogs/config"
2023-07-06 17:42:54 +00:00
"owl-blogs/domain/model"
2023-06-25 19:32:36 +00:00
"owl-blogs/infra"
"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-07-08 11:28:06 +00:00
config := config.NewConfig()
2023-07-06 17:42:54 +00:00
2023-07-08 11:28:06 +00:00
registry := app.NewEntryTypeRegistry()
2023-07-08 13:59:26 +00:00
registry.Register(&model.Image{})
registry.Register(&model.Article{})
2023-07-09 19:04:59 +00:00
registry.Register(&model.Page{})
registry.Register(&model.Recipe{})
registry.Register(&model.Note{})
2023-07-06 17:42:54 +00:00
2023-07-08 09:08:55 +00:00
entryRepo := infra.NewEntryRepository(db, registry)
binRepo := infra.NewBinaryFileRepo(db)
2023-07-08 11:28:06 +00:00
authorRepo := infra.NewDefaultAuthorRepo(db)
2023-07-08 09:08:55 +00:00
entryService := app.NewEntryService(entryRepo)
binaryService := app.NewBinaryFileService(binRepo)
2023-07-08 11:28:06 +00:00
authorService := app.NewAuthorService(authorRepo, config)
return web.NewWebApp(entryService, registry, binaryService, authorService)
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
}