chore: add readme md
This commit is contained in:
parent
59525d8a05
commit
662c552ebe
|
@ -16,7 +16,8 @@ COPY . .
|
|||
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y git
|
||||
apt-get install -y git && \
|
||||
mkdir /root/.ssh
|
||||
|
||||
# Make the root foler for our ssh
|
||||
RUN --mount=type=secret,id=ssh_key,dst=/root/.ssh/id_rsa \
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
# app:
|
||||
# image: igs170911/member:v1.0.4
|
||||
# container_name: app-service
|
||||
# ports:
|
||||
# - "8080:8080" # 替換為您的應用服務的公開端口
|
||||
# depends_on:
|
||||
# - mongo
|
||||
# - etcd
|
||||
# - redis
|
||||
# environment:
|
||||
# MONGO_URI: mongodb://mongo:27017/appdb
|
||||
# ETCD_ENDPOINT: http://etcd:2379
|
||||
# REDIS_HOST: redis
|
||||
# REDIS_PORT: 6379
|
||||
# networks:
|
||||
# - app-network
|
||||
app:
|
||||
image: igs170911/member:v1.0.4
|
||||
container_name: app-service
|
||||
ports:
|
||||
- "8080:8080" # 替換為您的應用服務的公開端口
|
||||
depends_on:
|
||||
- mongo
|
||||
- etcd
|
||||
- redis
|
||||
environment:
|
||||
MONGO_URI: mongodb://mongo:27017/appdb
|
||||
ETCD_ENDPOINT: http://etcd:2379
|
||||
REDIS_HOST: redis
|
||||
REDIS_PORT: 6379
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
mongo:
|
||||
image: mongo:8.0
|
||||
|
|
|
@ -2,7 +2,7 @@ Name: member.rpc
|
|||
ListenOn: 0.0.0.0:8080
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:2379
|
||||
- 127.0.0.1:2379
|
||||
Key: member.rpc
|
||||
|
||||
Cache:
|
||||
|
@ -11,12 +11,18 @@ Cache:
|
|||
CacheExpireTime: 1s
|
||||
CacheWithNotFoundExpiry: 1s
|
||||
|
||||
Redis:
|
||||
Host: 127.0.0.1:6379
|
||||
Type: node
|
||||
Tls: false
|
||||
Key: ""
|
||||
|
||||
Mongo:
|
||||
Schema: mongodb
|
||||
Host: 127.0.0.1
|
||||
User: "admin"
|
||||
Password: "123"
|
||||
Port: "27017"
|
||||
Host: "127.0.0.1:27017"
|
||||
User: "root"
|
||||
Password: "example"
|
||||
Port: ""
|
||||
Database: digimon_member
|
||||
ReplicaName: "rs0"
|
||||
MaxStaleness: 30m
|
||||
|
@ -32,12 +38,12 @@ Bcrypt:
|
|||
Cost: 10
|
||||
|
||||
GoogleAuth:
|
||||
ClientID:
|
||||
AuthURL:
|
||||
ClientID: xxx.apps.googleusercontent.com
|
||||
AuthURL: x
|
||||
|
||||
LineAuth:
|
||||
ClientID :
|
||||
ClientSecret :
|
||||
RedirectURI :
|
||||
ClientID : "200000000"
|
||||
ClientSecret : xxxxx
|
||||
RedirectURI : http://localhost:8080/line.html
|
||||
|
||||
Host: 127.0.0.1
|
220
readme.md
220
readme.md
|
@ -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.
|
Loading…
Reference in New Issue