feat: [#823] register service providers to bootstrap/providers.go - #115
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds support for registering service providers to bootstrap/providers.go while maintaining backward compatibility with the traditional app.go registration approach. The implementation uses environment-aware conditional logic to determine which registration method to use.
Key changes:
- Refactored setup logic to support both bootstrap and non-bootstrap provider registration patterns
- Upgraded dependencies including goravel/framework and numerous indirect dependencies
- Improved code organization by moving package-level variables into function scope
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| setup/setup.go | Refactored provider registration logic to conditionally register MinIO service provider in either app.go or bootstrap/providers.go based on environment setup detection |
| go.mod | Updated Go version to 1.24.0 and upgraded goravel/framework plus numerous indirect dependencies for compatibility |
| go.sum | Updated checksums corresponding to all dependency changes in go.mod |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| modify.When(func(_ map[string]any) bool { | ||
| return !env.IsBootstrapSetup() | ||
| }, modify.GoFile(appConfigPath). | ||
| Find(match.Imports()).Modify(modify.AddImport(modulePath)). | ||
| Find(match.Providers()).Modify(modify.Register(minioServiceProvider))), | ||
|
|
||
| // Add minio service provider to providers.go if using bootstrap setup | ||
| modify.When(func(_ map[string]any) bool { | ||
| return env.IsBootstrapSetup() | ||
| }, modify.AddProviderApply(modulePath, minioServiceProvider)), | ||
|
|
||
| // Add minio disk to filesystems.go | ||
| modify.GoFile(filesystemsConfigPath).Find(match.Imports()).Modify( | ||
| modify.AddImport(filesystemContract), | ||
| modify.AddImport(minioFacades, "miniofacades"), | ||
| ). | ||
| Find(filesystemsDisksConfig).Modify(modify.AddConfig("minio", config)). | ||
| Find(filesystemsConfig).Modify(modify.AddConfig("default", `"minio"`)), | ||
| ). | ||
| Uninstall( | ||
| modify.GoFile(path.Config("app.go")). | ||
| Find(match.Providers()).Modify(modify.Unregister("&minio.ServiceProvider{}")). | ||
| Find(match.Imports()).Modify(modify.RemoveImport(packages.GetModulePath())), | ||
| modify.GoFile(path.Config("filesystems.go")). | ||
| Find(match.Config("filesystems.disks")).Modify(modify.RemoveConfig("minio")). | ||
| Find(match.Imports()).Modify(modify.RemoveImport("github.com/goravel/framework/contracts/filesystem"), modify.RemoveImport("github.com/goravel/minio/facades", "miniofacades")). | ||
| Find(match.Config("filesystems")).Modify(modify.AddConfig("default", `"local"`)), | ||
| // Remove minio disk from filesystems.go | ||
| modify.GoFile(filesystemsConfigPath). | ||
| Find(filesystemsConfig).Modify(modify.AddConfig("default", `"local"`)). | ||
| Find(filesystemsDisksConfig).Modify(modify.RemoveConfig("minio")). | ||
| Find(match.Imports()).Modify( | ||
| modify.RemoveImport(filesystemContract), | ||
| modify.RemoveImport(minioFacades, "miniofacades"), | ||
| ), | ||
|
|
||
| // Remove minio service provider from app.go if not using bootstrap setup | ||
| modify.When(func(_ map[string]any) bool { | ||
| return !env.IsBootstrapSetup() | ||
| }, modify.GoFile(appConfigPath). | ||
| Find(match.Providers()).Modify(modify.Unregister(minioServiceProvider)). | ||
| Find(match.Imports()).Modify(modify.RemoveImport(modulePath))), | ||
|
|
||
| // Remove minio service provider from providers.go if using bootstrap setup | ||
| modify.When(func(_ map[string]any) bool { | ||
| return env.IsBootstrapSetup() | ||
| }, modify.RemoveProviderApply(modulePath, minioServiceProvider)), |
There was a problem hiding this comment.
[nitpick] The duplication of the conditional logic env.IsBootstrapSetup() in lines 41, 48, 71, and 78 could be reduced by extracting this check into a variable at the beginning of the function. This would make the code more maintainable and easier to test. For example:
isBootstrapSetup := env.IsBootstrapSetup()Then use isBootstrapSetup and !isBootstrapSetup in the modify.When conditions.
📑 Description
Closes goravel/goravel#823
This pull request updates dependencies and refactors the setup logic for integrating MinIO with the Goravel framework. The most significant changes are dependency upgrades in
go.modand a more flexible, environment-aware setup process insetup/setup.go.Dependency updates and additions:
github.com/goravel/framework,github.com/fsnotify/fsnotify,github.com/pelletier/go-toml/v2,github.com/pterm/pterm,github.com/sagikazarmark/locafero,github.com/sourcegraph/conc,github.com/spf13/afero,github.com/spf13/cast,github.com/spf13/pflag,github.com/spf13/viper,github.com/urfave/cli/v3,golang.org/x/crypto,golang.org/x/net,golang.org/x/text, and others. Several new indirect dependencies were also added, such asgithub.com/charmbracelet/bubbletea,github.com/samber/lo, and more. [1] [2] [3]Setup process refactor:
setup/setup.goto use environment-aware logic for registering the MinIO service provider, supporting both bootstrap and non-bootstrap setups. This includes conditional registration and unregistration of the provider in eitherapp.goorproviders.gobased on the environment, and improved handling of configuration and imports for the MinIO disk infilesystems.go. [1] [2]✅ Checks