Skip to content

Frankie0702111/go-todolist

Repository files navigation

Project description

重構專案架構以及 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.



這是一個簡單的待辦事項專案
備註:

  1. jwt-token TTL 時間預設 900 秒,中介層驗證 token TTL 成功時,計算該 token TTL 是否低於 5 分鐘,低於則重新給予一組新的 token。
  2. token 加入白名單機制,經由 redis 管理,使用者登出一併清除 redis token。
  3. 日誌輸出,預設採用日期分割檔案,如果需要按容量大小分割檔案請取消註解 utils/log/logBySize.go

It is a simple todo list project
Note:

  1. 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.
  2. The token is added to the whitelist mechanism, managed by redis, and the user logout to clear the redis token as well.
  3. Log output, default date split file, if you need to split the file by size please uncomment utils/log/logBySize.go.

Contents

Software requirement

Project plugins

How to build project

1.Clone GitHub project to local

git clone https://github.com/Frankie0702111/go-todolist.git

2.Generate .env and set up environment

cd go-todolist
cp .env.example .env

# Set up basic information, such as database, Google Oauth, JWT
vim .env

3.Build docker image and start

cd go-todolist

# Create docker image
docker compose build --no-cache

# Run docker
docker compose up -d

# Stop docker
docker compose stop

4.Generate db migrations

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

5.Build Swagger API documentation

make generate-api-doc

Folder structure

├── 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

Folder definition

  • 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

How to get telegram notifications

  1. Sign in to your Telegram account.
  2. Search for this account "@GolangToDoListBot" and press "Start".
  3. Input this command "/setaccess {Email}" to set your configuration.
  4. Input this command "/tasklist" to check for incomplete tasks.
  5. To be continued ...