DB Schema
User Table
Field | Type | GORM Options | JSON Key | Description |
---|---|---|---|---|
ID | string | type:varchar(36);primary_key | id | The unique identifier for the user. (from line account) |
Name | string | type:varchar(255);index | name | The name of the user. (from line account) |
User-Event Table
Field | Type | Description |
---|---|---|
user_id | varchar(36) | The ID of the user, linking to User.ID . |
event_id | varchar(36) | The ID of the event, linking to Event.ID . |
Event Table
Field | Type | GORM Options | JSON Key | Redis Key | Description |
---|---|---|---|---|---|
ID | *string | type:varchar(36);primary_key | id | id | The event ID defined at the frontend. If not provided, it is calculated by the hash of event detail and event time. |
EventTimeStart | *time.Time | type:timestamp | event_time_start | event_time_start | The start time of the event. |
EventTimeEnd | *time.Time | type:timestamp | event_time_end | event_time_end | The end time of the event. |
EventDetail | *string | type:varchar(1024) | event_detail | event_detail | The details of the event, stored in JSON format. This is parsed when sending to the line message API. |
心理測驗統計
- 結果種類儲存
- 統計趴數
Field | Type | GORM Options | Description |
---|---|---|---|
Type | string | type:varchar(255);unique | The unique type of the psycho test. |
Count | int | type:int | The count associated with the test. |
API
- Add type
- Retrieve statistic result
Line
Official Document
Tutorial
Line Login Integration Tutorial
Push Line Flex Message
- bike-festival-2024-backend/pkg/worker/event.go at main · gdsc-ncku/bike-festival-2024-backend (github.com)
- bike-festival-2024-backend/pkg/line_utils/flex.go at main · gdsc-ncku/bike-festival-2024-backend (github.com)
Asynq
- hibiken/asynq: Simple, reliable, and efficient distributed task queue in Go (github.com)
- hibiken/asynqmon: Web UI for Asynq task queue (github.com)
Add Scheduled Task
Cancel Scheduled Task
- asynq/inspector.go at master · hibiken/asynq (github.com)
- bike-festival-2024-backend/pkg/service/notify.go at main · gdsc-ncku/bike-festival-2024-backend (github.com)
Optimization
Get Event By EventID
DB only
(2000 virtual users, for 1 mins)
Redis Cache + DB
(2000 virtual users, for 1 mins)
1 | type EventCache struct { |
部署
Nginx Setup
Nginx Reverse Proxy
Note
要把 ssl_certificate & ssl_certificate_key
那邊的 domain 改成你自己的 (for Certbot)
1 | server { |
CertBot
1 | sudo apt install certbot |
Bug
Line login redirect
Warning
the bug is due to the referer-policy
the default policy is strict-origin-when-cross-origin
In my case, I use the additional redirect_path(which is set in query string ``) to compose the frontend redirect path:
It works fine when I am developing at my local computer, but in the production environment, it always redirect user to the page with duplicate path, like: /bikefest/main-stagebikefest/main-stage/
Then I discover that in my local development environment, the request referer only contain the domain name(localhost:5173
), but the production send its full path and query string to the backend server.
And that the reason is: in dev env, the frontend is at localhost:5173
and the backend is at localhost:8000
, the trigger the default referer policy strict-origin-when-cross-origin
only send the localhost:8000
as the referer value. In prod env, the frontend and backend have the same domain but only differ at the path, so the refer default policy send origin
, path
, query
as the referer value, and frontend also send its windows.location.path
as redirected_path
query string, then backend compose the referer
, redirect_path
, and the result would be like `https://
To resolve this problem, we only needs to set the referer policy in the nginx configuration, and let the referer only include origin
to prevent the above issue:
1 | server { |