app

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ConfigModule sets up the configuration dependencies for the application. It includes providers for logging, slot configuration, and Redis configuration.

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.

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.

View Source
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.

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:

  1. Creates a new fx application (`newApp`) with `RootModule` as its primary dependency injection module.
  2. Provides the CLI context as a dependency for use across the application.
  3. Sets up logging by injecting the `log.Config` and creating a new logger.
  4. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL