RapidGo
No results found

Hook System

Wire your application to the framework with 6 hooks.

The hook system is how your application code connects to the RapidGo framework. All hooks are set in cmd/main.go before calling cli.Execute().

Available Hooks

Hook Signature Purpose
SetBootstrap func(a *app.App, mode service.Mode) Register service providers
SetRoutes func(r *router.Router, c *container.Container, mode service.Mode) Register routes
SetJobRegistrar func() Register queue job handlers
SetScheduleRegistrar func(s *scheduler.Scheduler, a *app.App) Register scheduled tasks
SetModelRegistry func() []interface{} Return models for AutoMigrate
SetSeeder func(db *gorm.DB, name string) error Run database seeders

Complete Example

func main() {
    cli.SetBootstrap(func(a *app.App, mode service.Mode) {
        a.Register(&providers.ConfigProvider{})
        a.Register(&providers.DatabaseProvider{})
        a.Register(&providers.RouterProvider{Mode: mode})
    })

    cli.SetRoutes(func(r *router.Router, c *container.Container, mode service.Mode) {
        if mode.Has(service.ModeWeb) {
            routes.RegisterWeb(r)
        }
        if mode.Has(service.ModeAPI) {
            routes.RegisterAPI(r)
        }
    })

    cli.SetJobRegistrar(jobs.RegisterJobs)
    cli.SetScheduleRegistrar(schedule.RegisterSchedule)
    cli.SetModelRegistry(models.All)

    cli.SetSeeder(func(db *gorm.DB, name string) error {
        if name != "" {
            return seeders.RunByName(db, name)
        }
        return seeders.RunAll(db)
    })

    cli.Execute()
}

Why Hooks?

Hooks keep the framework and your application code cleanly separated. The framework (core/) never imports your application code — instead, your main.go tells the framework what to use via hooks. This means:

  • The framework can be updated independently
  • Your application structure is flexible
  • Testing is straightforward — you can set different hooks for test scenarios