How zihuangning/gogameserver works
Project Purpose and Type
• This is a game server project built in Go. Its purpose is to support an online game with various services (chat, game, login, API, etc.).
• The README indicates the use of Consul for service registration/discovery, protocol buffers for client communication, and multiple underlying data stores (MySQL, MongoDB, Redis). Services are built using a microservices-like architecture with TCP-based IPC and RPC channels.
Analyzing the File Structure
• Top-level directories include:
• config: Contains local configuration files (for MySQL, MongoDB, Redis, Consul, etc.).
• core: Contains the internal libraries and utilities—configuration handling, logging, database connectors, GRPC and RPC, JWT, session management, and other support libraries—all of which are common to many services.
• servives (likely meant to be “services”): Contains modular subdirectories for specific game server functions such as api, chat, connector, game, log, and login. Each directory has its own main entry point and additional submodules (controllers, models, cache, etc.) that implement service-specific logic.
• dbs: Holds database schema files (e.g., user.sql).
• scripts: Shell scripts for building, running, stopping, configuring, and generating protobuf files.
• Others: Test scripts and files indicating testing support (e.g., test/ directory).
Key Architectural Components
a. Service Registry & Communication Backbone:
• Consul: Highlight that Consul is used for service registration/discovery (config files present, and the core/libs/consul module).
• Communication protocols: Use of gRPC (see core/libs/grpc), IPC for inter-process communication using protobuf (tracked under core/messages, core/libs/grpc/ipc).
b. Core Libraries and Infrastructure:
• core: This layer abstracts common functionality such as configuration parsing, logging, session management, JWT handling, and database connections for MySQL, MongoDB, and Redis.
• Each of these libraries forms the basis of inter-service communication, error handling, and utility functions.
c. Microservice Components:
• API Service (servives/api): Acts as the front-facing application interface handling client requests.
• Chat Service (servives/chat): Handles chat-specific functionalities, including caching of online user data.
• Connector Service (servives/connector): Likely manages the connections between clients and backend services, complete with message processors and caching.
• Game Service (servives/game): Manages game-specific logic and user modules.
• Login Service (servives/login): Handles user authentication—caching, online sessions, and login routines.
• Log Service (servives/log): Dedicated to logging operations in the system.
• Public Shared Modules (servives/public): Contains shared code (e.g., error codes, proto definitions, Mongo/MySQL/Redis instance setups) that can be used by multiple services.
• Test Service/Entry: Used for testing functionality (found in servives/test and test directories).
d. Data Storage Components:
• Databases: MySQL and MongoDB databases (referenced in config files and core service modules).
• Caching: Redis is used as a cache layer, and some services (such as chat and login) include caching modules.
e. Protocols & Integration:
• Protocol Buffers: Used for client communications (with proto definitions in servives/public/gameProto and GRPC modules in core).
• TCP-based IPC, RPC: Services use these for inter-service interactions.
• Websocket/Socket: Parts of the code (in core/libs/socket and core/libs/websocket) may indicate real-time communication especially useful in gaming applications.