How liuguangw/billing_go works
Main Components
• Billing Server Binary: Represent the main executable (billing on Linux and billing.exe for Windows) that is started via main.go.
• Command/CLI Interface: The cmd/ folder contains commands (app_command.go, up, stop, version) that control server behavior (e.g., launching servers in daemon vs. foreground mode, stopping the server).
• Business Handlers: The bhandler/ package holds various handler implementations (such as login_handler, register_handler, enter_game_handler, etc.) that process different billing or game-specific commands.
• Data Models: The models/ directory contains definitions for handling accounts, login checks, and point conversion logic.
• Core Services:
• Billing Service: Located under services/billing; this module initializes the database, sets up listeners, configures logging, handles incoming billing packets, and manages user queries (e.g., show_users).
• Connection Handling: The services/handle package is responsible for managing low-level network tasks such as accepting connections, reading/writing packets, and enforcing policies (e.g., allowed addresses).
• Utility & Configuration Services: Other services (like load_server_config.go, packet_data_reader.go, process_attr_xxx.go, run_background.go, show_version_info.go) support system configuration, platform-specific functionalities, and run-time background tasks.
• External Components:
• Login Server: Since the README describes that only the “Login” server connects to billing, represent this external dependency.
• MySQL Database: The configuration file (config.yaml) indicates that billing communicates with a MySQL instance for account and related data.
• Log Files: Although not a software component per se, the billing log and Login server’s logs are critical for debugging and monitoring.
Relationships & Data Flow
• Flow from handlers (in bhandler/) to models – for instance, upon processing a login or registration request, business logic within models is called.
• Optionally, include the command-line control path: commands in cmd/ (up, stop, version) that send signals to the billing service.
Architectural Patterns & Design Principles
• Layered Architecture: Separate concerns into presentation (CLI via cmd/), application logic (handlers in bhandler and models), and infrastructural services (services for networking, logging, and configuration).
• Modular Organization: Different packages (bhandler, models, services, common) isolate functionality, which supports easier maintenance and potential scalability.
• Platform-Specific Handling: With files like process_attr_linux.go and process_attr_windows.go, indicate that the system contains specialized modules to handle cross-platform differences.