chore: add readme md

This commit is contained in:
王性驊 2025-02-08 10:23:09 +08:00
parent 59525d8a05
commit 662c552ebe
5 changed files with 254 additions and 27 deletions

View File

@ -16,7 +16,8 @@ COPY . .
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y git apt-get install -y git && \
mkdir /root/.ssh
# Make the root foler for our ssh # Make the root foler for our ssh
RUN --mount=type=secret,id=ssh_key,dst=/root/.ssh/id_rsa \ RUN --mount=type=secret,id=ssh_key,dst=/root/.ssh/id_rsa \

View File

View File

@ -1,22 +1,22 @@
version: "3.9" version: "3.9"
services: services:
# app: app:
# image: igs170911/member:v1.0.4 image: igs170911/member:v1.0.4
# container_name: app-service container_name: app-service
# ports: ports:
# - "8080:8080" # 替換為您的應用服務的公開端口 - "8080:8080" # 替換為您的應用服務的公開端口
# depends_on: depends_on:
# - mongo - mongo
# - etcd - etcd
# - redis - redis
# environment: environment:
# MONGO_URI: mongodb://mongo:27017/appdb MONGO_URI: mongodb://mongo:27017/appdb
# ETCD_ENDPOINT: http://etcd:2379 ETCD_ENDPOINT: http://etcd:2379
# REDIS_HOST: redis REDIS_HOST: redis
# REDIS_PORT: 6379 REDIS_PORT: 6379
# networks: networks:
# - app-network - app-network
mongo: mongo:
image: mongo:8.0 image: mongo:8.0

View File

@ -2,7 +2,7 @@ Name: member.rpc
ListenOn: 0.0.0.0:8080 ListenOn: 0.0.0.0:8080
Etcd: Etcd:
Hosts: Hosts:
- 127.0.0.1:2379 - 127.0.0.1:2379
Key: member.rpc Key: member.rpc
Cache: Cache:
@ -11,12 +11,18 @@ Cache:
CacheExpireTime: 1s CacheExpireTime: 1s
CacheWithNotFoundExpiry: 1s CacheWithNotFoundExpiry: 1s
Redis:
Host: 127.0.0.1:6379
Type: node
Tls: false
Key: ""
Mongo: Mongo:
Schema: mongodb Schema: mongodb
Host: 127.0.0.1 Host: "127.0.0.1:27017"
User: "admin" User: "root"
Password: "123" Password: "example"
Port: "27017" Port: ""
Database: digimon_member Database: digimon_member
ReplicaName: "rs0" ReplicaName: "rs0"
MaxStaleness: 30m MaxStaleness: 30m
@ -32,12 +38,12 @@ Bcrypt:
Cost: 10 Cost: 10
GoogleAuth: GoogleAuth:
ClientID: ClientID: xxx.apps.googleusercontent.com
AuthURL: AuthURL: x
LineAuth: LineAuth:
ClientID : ClientID : "200000000"
ClientSecret : ClientSecret : xxxxx
RedirectURI : RedirectURI : http://localhost:8080/line.html
Host: 127.0.0.1 Host: 127.0.0.1

220
readme.md
View File

@ -0,0 +1,220 @@
# 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.
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.
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
## Repository Structure
```
.
├── docker-compose.yml
├── etc/
│ ├── member.example.yaml
│ └── member.yaml
├── internal/
│ ├── config/
│ ├── logic/account/
│ ├── server/account/
│ └── svc/
├── member.go
├── pkg/
│ ├── domain/
│ ├── mock/
│ ├── repository/
│ └── usecase/
└── readme.md
```
### Key Files and Directories:
- `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
- MongoDB 8.0
- Etcd 3.5.5
- Redis 7.0
### Installation
1. Clone the repository:
```
git clone <repository_url>
cd <repository_directory>
```
2. Start the required services using Docker Compose:
```
docker-compose up -d
```
3. Copy the example configuration file and modify it as needed:
```
cp etc/member.example.yaml etc/member.yaml
```
4. Build and run the Member Service:
```
go build
./member
```
### Configuration
The `etc/member.yaml` file contains the main configuration for the Member Service. Key configuration options include:
- `ListenOn`: The address and port the service listens on
- `Etcd`: Configuration for Etcd connection
- `Cache`: Redis cache configuration
- `Mongo`: MongoDB connection details
- `Bcrypt`: Password hashing cost
- `GoogleAuth`: Google authentication settings
- `LineAuth`: LINE authentication settings
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",
})
```
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 ./...
```
### 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
^ |
| |
+---------------------------------------------------------+
```
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)
## Deployment
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.