重構專案架構以及 API,特別是存在風險的 Task api,於新的專案中這些問題已被完美的處理。
新專案的位置
添加 : 單元測試、整合測試 (僅限部分範例)
取消 : 日誌輸出、IP 請求上限
The refactoring of the project architecture and API, especially the risky Task api, has been handled perfectly in the new project.
New project location
Add : Unit test, integration test (only for some cases).
Cancel : Log output, IP request limit.
這是一個簡單的待辦事項專案
備註:
- jwt-token TTL 時間預設 900 秒,中介層驗證 token TTL 成功時,計算該 token TTL 是否低於 5 分鐘,低於則重新給予一組新的 token。
- token 加入白名單機制,經由 redis 管理,使用者登出一併清除 redis token。
- 日誌輸出,預設採用日期分割檔案,如果需要按容量大小分割檔案請取消註解
utils/log/logBySize.go
。
It is a simple todo list project
Note:
- jwt-token TTL time is preset to 900 seconds. When the middleware verifies the success of token TTL, it will calculate whether the token TTL is lower than 5 minutes, and if it is lower, a new set of token will be given again.
- The token is added to the whitelist mechanism, managed by redis, and the user logout to clear the redis token as well.
- Log output, default date split file, if you need to split the file by size please uncomment
utils/log/logBySize.go
.
- Software requirements
- Project plugins
- How to build project
- Folder structure
- Folder definition
- How to get telegram notifications
- Database
- Programming language
- Go: v1.19
- Deveops
- Other
- Gin
- GORM
- MySQL
- GoDotEnv
- crypto
- smapping
- golang-jwt
- go-redis
- zap
- lumberjack
- file-rotatelogs
- oauth2
- gjson
- aws sdk for go v2
- uuid
git clone https://github.com/Frankie0702111/go-todolist.git
cd go-todolist
cp .env.example .env
# Set up basic information, such as database, Google Oauth, JWT
vim .env
cd go-todolist
# Create docker image
docker compose build --no-cache
# Run docker
docker compose up -d
# Stop docker
docker compose stop
cd go-todolist
# Up all migration
make migrate-up
# Down all migration
make migrate-down
# Specify batch up or down (If you want to go down to a specific file, it is recommended to open a new folder)
make migrate-up number=1
make migrate-down number=1
make generate-api-doc
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── controller
│ ├── categoryController.go
│ ├── googleOauthController.go
│ ├── taskController.go
│ └── userController.go
├── docker-compose.yaml
├── docs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── entity
│ ├── categoryEntity.go
│ ├── redisEntity.go
│ ├── s3Entity.go
│ ├── taskEntity.go
│ └── userEntity.go
├── go.mod
├── go.sum
├── log
├── main.go
├── middleware
│ ├── cors.go
│ ├── jwt.go
│ └── rateLimiter.go
├── migrations
│ ├── 20221129000000_create_users_table.down.sql
│ ├── 20221129000000_create_users_table.up.sql
│ ├── 20221129000001_create_categories_table.down.sql
│ ├── 20221129000001_create_categories_table.up.sql
│ ├── 20221129000002_create_tasks_table.down.sql
│ └── 20221129000002_create_tasks_table.up.sql
├── model
│ ├── category.go
│ ├── task.go
│ └── user.go
├── request
│ ├── categoryRequest.go
│ ├── publicRequest.go
│ ├── taskRequest.go
│ └── userRequest.go
├── router
│ └── api.go
├── services
│ ├── categoryService.go
│ ├── jwtService.go
│ ├── taskService.go
│ └── userService.go
└── utils
├── aws
│ └── s3.go
├── civilDatetime
│ └── civilDatetime.go
├── gorm
│ └── gorm.go
├── log
│ ├── logByDate.go
│ └── logBySize.go
├── paginator
│ └── paginator.go
├── redis
│ └── redis.go
└── responses
└── response.go
- Controller
接收 HTTP request 調用 request & service
Receiving HTTP requests calling requests and services
- Docs
Swagger API 文件位置
Swagger API documentation location
- Entity
協助 service 調用 sql query
Assist service in calling sql query
- Log
日誌檔位置
Location of logger files
- Middleware
中介層,負責過濾進入的資料
Intermediary layer, responsible for filtering incoming data
- Migration
建立 datatable 詳細資訊
Create datatable details
- Model
作為返回的對象
As a returned object
- Request
協助 controller 驗證 request parameters
Assist controller validation request parameters
- Router
API 路由位置
API route locations
- Service
協助 controller 處理業務邏輯
Assist controller with business logic
- Utils
模組化程式碼置放處,提供專案調用
Modular code placement for project calls
- Sign in to your Telegram account.
- Search for this account "@GolangToDoListBot" and press "Start".
- Input this command "/setaccess {Email}" to set your configuration.
- Input this command "/tasklist" to check for incomplete tasks.
- To be continued ...