app-cloudep-member-server/readme.md

133 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 會員服務:用戶帳號管理系統
會員服務是一個完整的用戶帳號管理系統, 負責用戶身份驗證、帳號創建及個人資料管理。
<br>
此服務為需要用戶管理功能的應用程式提供穩健的後端,支援多種身份驗證方式,並可與外部服務整合。
本系統採用微服務架構,利用 MongoDB 作為資料存儲、Redis 作為快取,並使用 Etcd 進行分散式配置管理。其功能涵蓋用戶註冊、帳號綁定、個人資料管理,以及支援 Google 和 LINE 等第三方身份驗證服務。
## 核心功能
- 用戶帳號的建立與管理
- 多種身份驗證方式Email、手機、Google、LINE
- 跨平台帳號綁定
- 用戶個人資料管理
- 生成及驗證 綁定以及忘記密碼的 code
- 可擴展的微服務架構
- 整合 MongoDB、Redis 和 Etcd
- 支援 Docker 進行部署與擴展
## 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
```
### 主要檔案與目錄:
- `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`:會員服務的主要進入點
## 使用說明
### 先決條件
- Go 1.23.1 或更新版本
- Docker 及 Docker Compose
- MongoDB 8.0
- Etcd 3.5.5
- Redis 7.0
### 安裝依賴項目
```bash
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. 複製範例設定檔並根據需求修改:
```bash
cp etc/member.example.yaml etc/member.yaml
```
4. 執行會員服務:
```golang
go mod tidy
go run member.go
```
### 設定
etc/member.yaml 是會員服務的主要設定檔,關鍵設定包括:
- `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.
### Make
1. To run the test suite:
```bash
make test
```
2. Golint and sort import
```bash
make fmt
```
3. 格式化與 lint
```bash
make fmt
```
4. 產生 mock.
```bash
make mock-gen
```
5. 產生 rpc data(有改io的話).
```bash
make gen-rpc
```