Compare commits

..

2 Commits

Author SHA1 Message Date
王性驊 714163bbe6 chore: add readme md 2025-02-08 14:07:13 +08:00
王性驊 7ec0670121 chore: add readme md 2025-02-08 14:06:19 +08:00
1 changed files with 75 additions and 162 deletions

237
readme.md
View File

@ -1,20 +1,21 @@
# Member Service: User Account Management System
# 會員服務:用戶帳號管理系統
The Member Service is a comprehensive user account management system designed to handle user authentication, account creation, and profile management. This service provides a robust backend for applications requiring user management functionality, supporting various authentication methods and integrating with external services.
會員服務是一個完整的用戶帳號管理系統, 負責用戶身份驗證、帳號創建及個人資料管理。
<br>
此服務為需要用戶管理功能的應用程式提供穩健的後端,支援多種身份驗證方式,並可與外部服務整合。
The system is built using a microservices architecture, leveraging technologies such as MongoDB for data storage, Redis for caching, and Etcd for distributed configuration. It offers a wide range of features including user registration, account binding, profile management, and support for third-party authentication providers like Google and LINE.
本系統採用微服務架構,利用 MongoDB 作為資料存儲、Redis 作為快取,並使用 Etcd 進行分散式配置管理。其功能涵蓋用戶註冊、帳號綁定、個人資料管理,以及支援 Google 和 LINE 等第三方身份驗證服務。
Key features of the Member Service include:
- User account creation and management
- Multiple authentication methods (email, phone, Google, LINE)
- Account binding for different platforms
- User profile management
- Refresh token generation and verification
- Scalable architecture using microservices
- Integration with MongoDB, Redis, and Etcd
- Docker support for easy deployment and scaling
## 核心功能
- 用戶帳號的建立與管理
- 多種身份驗證方式Email、手機、Google、LINE
- 跨平台帳號綁定
- 用戶個人資料管理
- 生成及驗證 綁定以及忘記密碼的 code
- 可擴展的微服務架構
- 整合 MongoDB、Redis 和 Etcd
- 支援 Docker 進行部署與擴展
## Repository Structure
```
@ -37,57 +38,62 @@ Key features of the Member Service include:
└── readme.md
```
### Key Files and Directories:
### 主要檔案與目錄:
- `docker-compose.yml`:定義多容器 Docker 環境
- `etc/member.yaml`:會員服務的設定檔
- `internal/`:內部應用程式代碼
- `logic/account/`:帳號相關的業務邏輯
- `server/account/`:帳號服務的 gRPC 伺服器實作
- `pkg/`:可重複使用的程式碼模組
- `domain/`const、interface、error code、redis key 等定義
- `repository/`:資料存取層的實作
- `usecase/`:使用案例實作
- `member.go`:會員服務的主要進入點
- `docker-compose.yml`: Defines the multi-container Docker environment
- `etc/member.yaml`: Configuration file for the Member Service
- `internal/`: Contains internal application code
- `logic/account/`: Business logic for account-related operations
- `server/account/`: gRPC server implementation for account service
- `pkg/`: Reusable package code
- `domain/`: Domain models and interfaces
- `repository/`: Data access layer implementations
- `usecase/`: Use case implementations
- `member.go`: Main entry point for the Member Service
## 使用說明
## Usage Instructions
### Prerequisites
- Go 1.16 or later
- Docker and Docker Compose
### 先決條件
- Go 1.23.1 或更新版本
- Docker 及 Docker Compose
- MongoDB 8.0
- Etcd 3.5.5
- Redis 7.0
### Installation
### 安裝依賴項目
```bash
1. Clone the repository:
```
git clone <repository_url>
cd <repository_directory>
go install github.com/zeromicro/go-zero/tools/goctl@latest // goctl 安裝
go install golang.org/x/tools/cmd/goimports@latest
# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.63.4
golangci-lint --version
````
### 本地開發
1. 克隆專案:
```bash
git clone git@git.30cm.net:digimon/app-cloudep-member-server.git
cd app-cloudep-member-server
```
2. Start the required services using Docker Compose:
```
docker-compose up -d
```
3. Copy the example configuration file and modify it as needed:
```
2. 複製範例設定檔並根據需求修改:
```bash
cp etc/member.example.yaml etc/member.yaml
```
4. Build and run the Member Service:
```
go build
./member
4. 執行會員服務:
```golang
go mod tidy
go run member.go
```
### Configuration
The `etc/member.yaml` file contains the main configuration for the Member Service. Key configuration options include:
### 設定
etc/member.yaml 是會員服務的主要設定檔,關鍵設定包括:
- `ListenOn`: The address and port the service listens on
- `Etcd`: Configuration for Etcd connection
- `Cache`: Redis cache configuration
@ -98,123 +104,30 @@ The `etc/member.yaml` file contains the main configuration for the Member Servic
Ensure all configuration values are set correctly before starting the service.
### Common Use Cases
1. Creating a new user account:
```go
resp, err := accountService.CreateUserAccount(ctx, &account.CreateUserAccountReq{
Email: "user@example.com",
Password: "securepassword",
})
```
### Make
2. Authenticating a user:
```go
resp, err := accountService.VerifyPlatformAuthResult(ctx, &account.VerifyPlatformAuthResultReq{
Platform: member.Platform_EMAIL,
Email: "user@example.com",
Password: "securepassword",
})
```
3. Updating user information:
```go
resp, err := accountService.UpdateUserInfo(ctx, &account.UpdateUserInfoReq{
Uid: "user123",
Nickname: "New Nickname",
})
```
### Testing & Quality
To run the test suite:
```
go test ./...
1. To run the test suite:
```bash
make test
```
### Troubleshooting
1. Connection issues with MongoDB:
- Ensure MongoDB is running and accessible
- Check the MongoDB connection string in `etc/member.yaml`
- Verify network connectivity between the service and MongoDB
2. Authentication failures:
- Double-check the configuration for Google and LINE authentication in `etc/member.yaml`
- Ensure the correct client IDs and secrets are set
3. Performance issues:
- Monitor Redis cache usage and adjust cache settings if necessary
- Check MongoDB query performance and add indexes if needed
- Use Go's pprof tool to profile the application:
```
go tool pprof http://localhost:8080/debug/pprof/profile
```
## Data Flow
The Member Service follows a typical request-response flow:
1. Client sends a request to the gRPC server
2. Server routes the request to the appropriate logic handler
3. Logic handler processes the request, interacting with repositories as needed
4. Repositories interact with the database (MongoDB) or cache (Redis)
5. Results are returned through the logic handler back to the client
```
Client -> gRPC Server -> Logic Handler -> Repository -> Database/Cache
^ |
| |
+---------------------------------------------------------+
2. Golint and sort import
```bash
make fmt
```
Important technical considerations:
- Use of caching to improve performance for frequently accessed data
- Proper error handling and logging throughout the flow
- Secure handling of sensitive information (e.g., passwords, tokens)
3. 格式化與 lint
```bash
make fmt
```
## Deployment
4. 產生 mock.
```bash
make mock-gen
```
The Member Service can be deployed using Docker containers. The `docker-compose.yml` file provides a template for deploying the service along with its dependencies (MongoDB, Etcd, and Redis).
To deploy:
1. Ensure Docker and Docker Compose are installed on the target system
2. Modify the `docker-compose.yml` file if necessary (e.g., to change ports or add volumes)
3. Run the following command in the project root:
```
docker-compose up -d
```
4. Monitor the logs to ensure all services start correctly:
```
docker-compose logs -f
```
For production deployments, consider using orchestration tools like Kubernetes for better scalability and management.
## Infrastructure
The Member Service relies on the following infrastructure components:
- MongoDB (mongo):
- Image: mongo:8.0
- Purpose: Primary data storage for user accounts and related information
- Configuration:
- Root username and password set via environment variables
- Etcd (etcd):
- Image: quay.io/coreos/etcd:v3.5.5
- Purpose: Distributed key-value store for service discovery and configuration
- Configuration:
- Listens on port 2379 for client connections
- Data directory set to /etcd-data
- Redis (redis):
- Image: redis:7.0
- Purpose: Caching layer for improved performance
- Configuration:
- Default configuration with no password
These infrastructure components are defined in the `docker-compose.yml` file, allowing for easy local development and testing. For production deployments, these services should be properly secured and scaled according to the application's needs.
5. 產生 rpc data(有改io的話).
```bash
make gen-rpc
```