module
Version:
v0.0.0-...-9443f7e
Opens a new window with list of versions in this module.
Published: Mar 15, 2024
License: MIT
Opens a new window with license information.
README
¶
Simple Recommend API
此專案滿足以下測驗需求
-
註冊
- 帳號要求: 使用者必須註冊一個以 email 為帳號的用戶。
- 密碼強度: 密碼長度必須介於 6 到 16 個字符之間,並且至少包含一個大寫字母、一個小寫字母和一個特殊符號。
-
驗證 Email
- 使用者註冊後,系統會發送一封包含驗證連結的 email 到他們的郵箱。
- 使用者需要點擊該連結或輸入接收到的驗證碼以完成 email 驗證過程。
-
登入
-
獲取推薦商品
- 接口:
GET /recommendation
- 訪問限制: 使用者必須登入後才能訪問此接口。
- 功能描述: 此接口回應用戶推薦的商品資料。
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
- Go (Version 1.22 or later)
- Docker (運作開發環境需要的 MYSQL & Redis)
- Migrate (用於 dev 環境快速建立 DB table)
- Sqlc (A SQL Compiler, optional, 如果要動到 CRUD 的部分才要安裝)
Running Locally
To run the SimpleRecommend API locally for debugging purposes, follow these steps:
-
準備開發環境
確保您的開發環境中的 3306 (MySQL) 和 6379 (Redis) 端口未被佔用,因為我們將使用 Docker 來建立 MySQL 和 Redis 實例。請按照以下步驟使用我們在專案根目錄提供的 docker-compose.yaml 文件:
docker-compose -p simplerecommend up -d
-
Download the Go modules required by the project:
go mod download
-
基於您已經安裝 Migrate 和 啟動 MySQL&Redis
migrate -path scripts/db/migration -database "mysql://user:password@tcp(localhost:3306)/simplerecommend?multiStatements=true" -verbose up
-
.env
cp env.dev .env
注意!! EMAIL_SENDER_PASSWORD 不提供,如果要驗證寄信,請換上自己的 AppPassword
-
將開發用的 Postman collection 匯入 (節省檢查時間), 檔案位於
./scripts/postman/simplerecommend.postman_collection.json
-
Run the application:
go run ./cmd/main.go
功能驗證(happy case 展示)
happy case 系統 log

註冊成功 >> 寄信 >> 使用 code 驗證通過 >> login >> 存取 /recommendation
- 剛註冊成功的時候屬於尚未驗證狀態

- 收到信件(由於放上 github 會抽掉 EMAIL_SENDER_PASSWORD 如果要驗這部分要抽換自己的 EMAIL_SENDER_PASSWORD)

- 用 postman 模擬使用者點擊了連結, 可以參考 happy case 系統 log
- 使用者帳號被刷上 is_valid true & verified_at

- 使用者 login 成功, 可以參考 happy case 系統 log
- 使用者 access /recommendation, log 中可以看到一開始花了 2 秒(我開發時覺得等3秒覺得有點久就改成2秒), 之後靠 redis 變成微秒
Directories
¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pkg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Click to show internal directories.
Click to hide internal directories.