Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigModule = fx.Module("config", fx.Provide(config.GetLogConfig), fx.Provide(config.GetSlotConfig), fx.Provide(redis.GetRedisConfig), )
ConfigModule sets up the configuration dependencies for the application. It includes providers for logging, slot configuration, and Redis configuration.
var Controllers = fx.Provide( controller.NewUserController, controller.NewStatusController, controller.NewWalletController, controller.NewSlotController, )
Controllers defines providers for HTTP controllers, responsible for handling HTTP requests and interacting with the service layer. This includes controllers for user management, system status, wallet operations, and slot game endpoints.
var Repositories = fx.Provide( repository.NewUserRepository, repository.NewSlotRepository, )
Repositories defines providers for the repository layer, which is responsible for data persistence and retrieval logic. Includes providers for UserRepository and SlotRepository, which handle user data and slot game data, respectively.
var RootModule = fx.Module("server", Repositories, Services, Controllers, ConfigModule, database.DBModule, server.Module, redis.Module, fx.Provide(log.NewLogger), fx.Invoke(func(router *gin.Engine, userController *controller.UserController, statusController *controller.StatusController, walletController *controller.WalletController, slotController *controller.SlotController, ) { router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) initController(router, userController) initController(router, statusController) initController(router, walletController) initController(router, slotController) }), )
RootModule orchestrates the complete application setup, assembling repositories, services, controllers, and configurations into an fx.Module for dependency injection.
Additionally, it sets up Swagger API documentation, initializes HTTP controllers, and enables logging capabilities.
var Services = fx.Provide( service.NewUserService, service.NewSlotService, )
Services defines providers for the service layer, which contains business logic. It includes UserService and SlotService, handling operations related to user management and slot game logic.
Functions ¶
func RunServer ¶
func RunServer(c *cli.Context) error
RunServer initializes and runs the server within an fx application lifecycle. It provides the CLI context, sets up logging, and manages the HTTP server lifecycle.
Parameters:
- c: *cli.Context, a context object from the CLI, containing configuration and command line arguments.
Returns:
- error: An error indicating the outcome of the server startup, or nil if the server runs successfully.
Workflow:
- Creates a new fx application (`newApp`) with `RootModule` as its primary dependency injection module.
- Provides the CLI context as a dependency for use across the application.
- Sets up logging by injecting the `log.Config` and creating a new logger.
- Configures the HTTP server lifecycle, handling start and graceful shutdown operations.
Lifecycle Management:
- OnStart: Launches the HTTP server in a separate goroutine to avoid blocking and logs the server start.
- OnStop: Gracefully shuts down the HTTP server by calling `srv.Shutdown`, waiting for ongoing requests to finish.
Example usage:
err := RunServer(cliContext) if err != nil { log.Fatalf("Failed to run server: %v", err) }
Types ¶
This section is empty.