support queue

This commit is contained in:
yanghao05
2023-06-19 15:12:28 +08:00
parent 6b3bc9d944
commit 3ef841c211
4 changed files with 188 additions and 275 deletions

View File

@@ -41,11 +41,6 @@ func Serve(providers container.Providers, opts ...Option) error {
return LoadProviders(cfgFile, rootCmd.Use, providers)
}
withMigrationCommand(rootCmd)
withModelCommand(rootCmd)
withSeederCommand(rootCmd)
withServiceInstall(rootCmd)
return rootCmd.Execute()
}
@@ -124,8 +119,10 @@ func Config(file string) Option {
}
}
func Seeders(seeders ...contracts.SeederProvider) Option {
func CmdSeeders(seeders ...contracts.SeederProvider) Option {
return func(cmd *cobra.Command) {
withSeederCommand(cmd)
for _, seeder := range seeders {
if err := container.Container.Provide(seeder, dig.Group("seeders")); err != nil {
log.Fatal(err)
@@ -134,8 +131,10 @@ func Seeders(seeders ...contracts.SeederProvider) Option {
}
}
func Migrations(migrations ...contracts.MigrationProvider) Option {
func CmdMigrations(migrations ...contracts.MigrationProvider) Option {
return func(cmd *cobra.Command) {
withMigrationCommand(cmd)
for _, migration := range migrations {
if err := container.Container.Provide(migration, dig.Group("migrations")); err != nil {
log.Fatal(err)
@@ -143,3 +142,21 @@ func Migrations(migrations ...contracts.MigrationProvider) Option {
}
}
}
func CmdModel() Option {
return func(cmd *cobra.Command) {
withModelCommand(cmd)
}
}
func CmdService() Option {
return func(cmd *cobra.Command) {
withServiceInstall(cmd)
}
}
func CmdQueue() Option {
return func(cmd *cobra.Command) {
withQueueCommand(cmd)
}
}