# Golang Grpc 共享mod微服务框架 **Repository Path**: trident-framework/golang-microgrpc-sharemod ## Basic Information - **Project Name**: Golang Grpc 共享mod微服务框架 - **Description**: Golang Grpc 共享mod微服务框架 可运行golang版本【v1.18、v1.19、v1.20、v1.21、v1.22、1.23】 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-30 - **Last Updated**: 2026-01-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # golang-microgrpc-sharemod This is a microservices project based on the Go programming language, containing multiple service modules such as the gateway service, user service, and common service. This project uses gRPC as the inter-service communication protocol and supports multiple service discovery and configuration centers, such as Nacos and Consul. ## Project Structure - **gateway-api**: Gateway service responsible for receiving external requests and routing them to the corresponding services. - **services/common-service**: Common service providing basic functionalities for other services to call. - **services/user-service**: User service handling user-related business logic. ``` golang-microgrpc-sharemod/ ├── gateway-api/ # 网关服务 | ├── config/ # 配置目录 | ├── constants/ # 常量目录 | ├── controllers/ # 控制器目录 | ├── logs/ # 日志目录 | ├── middlewares/ # 中间件目录 | ├── routers/ # 路由目录 | ├── static/ # 静态目录 | ├── utils/ # 工具目录 | ├── deploy.yaml # k8s部署文件 | ├── docker_compose_Jenkinsfile # docker-compose CICD文件 | ├── docker-compose.yaml # docker-compose部署文件 | ├── Dockerfile # 构建镜像文件 | ├── k8s_Jenkinsfile # k8s CICD文件 | ├── kubesphere_Jenkinsfile # kubesphere CICD文件 | └── main.go # 主文件 ├── services/ | ├── common-service/ # 通用服务 | | ├── config/ # 配置目录 | | ├── constants/ # 常量目录 | | ├── handler/ # 处理器目录 | | ├── interceptors/ # 拦截器目录 | | ├── logs/ # 日志目录 | | ├── models/ # 模型目录 | | ├── proto/ # proto目录 | | ├── utils/ # 工具目录 | | ├── deploy.yaml # k8s部署文件 | | ├── docker_compose_Jenkinsfile # docker-compose CICD文件 | | ├── docker-compose.yaml # docker-compose部署文件 | | ├── Dockerfile # 构建镜像文件 | | ├── k8s_Jenkinsfile # k8s CICD文件 | | ├── kubesphere_Jenkinsfile # kubesphere CICD文件 | | └── main.go # 主文件 | ├── user-service/ # 用户服务 | | ├── config/ # 配置目录 | | ├── constants/ # 常量目录 | | ├── handler/ # 处理器目录 | | ├── interceptors/ # 拦截器目录 | | ├── logs/ # 日志目录 | | ├── models/ # 模型目录 | | ├── proto/ # proto目录 | | ├── utils/ # 工具目录 | | ├── deploy.yaml # k8s部署文件 | | ├── docker_compose_Jenkinsfile # docker-compose CICD文件 | | ├── docker-compose.yaml # docker-compose部署文件 | | ├── Dockerfile # 构建镜像文件 | | ├── k8s_Jenkinsfile # k8s CICD文件 | | ├── kubesphere_Jenkinsfile # kubesphere CICD文件 | | └── main.go # 主文件 ├── go.mod ├── go.sum └── README.md ``` ## Features - Supports multiple service discovery mechanisms (Nacos, Consul, Etcd) - Supports multiple configuration centers (Nacos, Consul, Etcd) - Provides gRPC service communication - Supports multiple data storages such as Redis, MySQL, and MongoDB - Offers functionalities such as logging, rate limiting, circuit breaking, and message queuing - Provides security mechanisms such as JWT authentication and access control ## Installation and Deployment ### Environment Requirements - Go 1.18+ - Docker 19+ - gRPC support - Redis, MySQL, MongoDB (install as needed) ### Building and Running 1. **Clone the Project** ```bash git clone https://gitee.com/trident-framework/golang-microgrpc-sharemod.git cd golang-microgrpc-sharemod ``` 2. **Build Services** Build service images using Docker: ```bash # Build gateway service cd gateway-api docker build -t gateway-api . # Build user service cd ../services/user-service docker build -t user-service . # Build common service cd ../common-service docker build -t common-service . ``` 3. **Run Services** Start services using `docker-compose`: ```bash docker-compose up -d ``` Or run manually: ```bash docker run -d -p 8080:8080 --name gateway-api gateway-api docker run -d -p 50051:50051 --name user-service user-service docker run -d -p 50052:50052 --name common-service common-service ``` ## Usage Instructions ### Gateway Service API Example - **User Login** ```http POST /api/v1/user/login { "username": "test", "password": "123456" } ``` - **Get User Information** ```http GET /api/v1/user/1 ``` ### gRPC Invocation Example The user service provides gRPC interfaces for other services to call, for example: ```protobuf // User service interface service UserSrv { rpc UserDetail(UserDetailRequest) returns (UserResponse); } ``` Invoking method: ```go conn, _ := grpc.Dial("user-service:50051", grpc.WithInsecure()) client := pbUser.NewUserSrvClient(conn) resp, _ := client.UserDetail(ctx, &pbUser.UserDetailRequest{Uid: 1}) ``` ## Configuration Instructions All services support configuration via configuration files located in the `config/` directory. The following configuration files are supported: - `app.yml`: Basic service configuration (port, environment, etc.) - `nacos.yml` / `consul.yml`: Service discovery and configuration center configuration - `redis.yml` / `mysql.yml`: Database connection configuration - `sentinel.yaml`: Rate limiting and circuit breaking configuration ## Logging and Monitoring - Uses `zap` as the logging framework, supporting structured logging - Supports integration with Jaeger for distributed tracing - Provides Prometheus metrics exposure interface for monitoring service status ## Development and Contributions Contributions of code and documentation are welcome. Please follow these steps: 1. Fork the project 2. Create a new branch (`git checkout -b feature/new-feature`) 3. Commit changes (`git commit -am 'Add new feature'`) 4. Push the branch (`git push origin feature/new-feature`) 5. Create a Pull Request ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.