diff --git a/README.md b/README.md index e50fecc..2eb2093 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@

- Shorts Logo + Shorts Logo

-

短褲

+

短褲 Shorts

-

一個極簡的短網址伺服器

+

A lightweight URL shortener built with Go

-## 用 +

中文版本

-1. 設 +## Features + +### Hot-Reloading Configuration + +Edit the `config/redirects.toml` file and Shorts will automatically reload the configuration. ```toml # config/redirects.toml @@ -17,68 +21,103 @@ "discord" = "https://discord.gg/9yYtgA4HXz" [permanent] -"tat/android" = "https://play.google.com/store/apps/details?id=club.ntut.npc.tat" -"tat/ios" = "https://apps.apple.com/tw/app/id1513875597" +"google" = "https://www.google.com" ``` -2. 開 +### Temporary and Permanent Redirects + +Add experimental redirects as temporary redirects (307) and change them to permanent redirects (301) for faster redirection. + +With the above configuration: ```sh -go run main.go +curl -v localhost:8080/discord ``` -3. 試 - ```text -$ http :8080/discord -HTTP/1.1 302 Found -Content-Length: 52 -Content-Type: text/html; charset=utf-8 -Date: Mon, 19 Aug 2024 15:04:49 GMT -Location: https://discord.gg/9yYtgA4HXz - -Found.. +< HTTP/1.1 302 Found +< Content-Type: text/html; charset=utf-8 +< Location: https://discord.gg/9yYtgA4HXz +< Date: Sun, 08 Sep 2024 14:28:11 GMT +< Content-Length: 52 +< +Found. +``` + +```sh +curl -v localhost:8080/google ``` ```text -$ http :8080/tat/android -HTTP/1.1 301 Moved Permanently -Content-Length: 98 -Content-Type: text/html; charset=utf-8 -Date: Mon, 19 Aug 2024 15:04:03 GMT -Location: https://play.google.com/store/apps/details?id=club.ntut.npc.tat - -Moved Permanently. +< HTTP/1.1 301 Moved Permanently +< Content-Type: text/html; charset=utf-8 +< Location: https://www.google.com +< Date: Mon, 09 Sep 2024 08:38:22 GMT +< Content-Length: 57 +< +Moved Permanently. ``` -4. 查 +### Viewing Statistics + +Shorts records the number of visitors and the last visited time for each redirect in `config/stats.json`. ```json -// config/stats.json { "discord": { "visitors": 1, - "last_visited": "2024-08-20T17:49:36.57603941+08:00" + "last_visited": "2024-09-08T22:28:11.894270007+08:00" }, - "tat/android": { + "google": { "visitors": 1, - "last_visited": "2024-08-20T17:49:42.709932014+08:00" + "last_visited": "2024-09-09T16:38:22.113075596+08:00" } } ``` -## 架 +## Deployment -1. 做 +We recommend deploying Shorts using Docker. + +### Docker ```sh -docker build -t shorts . +docker run -d -p 8080:8080 \ + -v $PWD/config:/config \ + ghcr.io/ntut-npc/shorts ``` -2. 起 +### Docker Compose -```sh -docker run -p 80:8080 -v ./config:/config shorts -``` +See [docs/compose.yaml](docs/compose.yaml) for an example Docker Compose configuration. + +## Development + +To set up Shorts for local development: + +1. Clone the repository: + + ```sh + git clone https://github.com/ntut-npc/shorts.git + cd shorts + ``` + +2. Install dependencies: + + ```sh + go mod download + ``` + +3. Run the application: + + ```sh + go run . + ``` + +The server will start on `http://localhost:8080`. + +### Hot Reloading During Development + +For a better development experience, we recommend using [gow](https://github.com/mitranim/gow), which automatically restarts the application when source files change. -或看 [compose.yaml](docs/compose.yaml)。 +Remember to create and configure your `config/redirects.toml` file as described in the [Hot-Reloading Configuration](#hot-reloading-configuration) section to set up your redirects. diff --git a/README.zh.md b/README.zh.md new file mode 100644 index 0000000..fdd8034 --- /dev/null +++ b/README.zh.md @@ -0,0 +1,121 @@ +

+ Shorts Logo +

+ +

短褲 Shorts

+ +

一個使用 Go 語言製作的輕量短網址服務

+ +## 功能 + +### 即時重新載入設定 + +編輯 `config/redirects.toml` 文件,Shorts 會自動重新載入設定。 + +```toml +# config/redirects.toml + +[temporary] +"discord" = "https://discord.gg/9yYtgA4HXz" + +[permanent] +"google" = "https://www.google.com" +``` + +### 臨時和永久重新導向 + +可以將實驗性的連結添加為臨時重新導向(307),然後將它們改成永久重新導向(301)以加快重新導向速度。 + +基於上述設定: + +```sh +curl -v localhost:8080/discord +``` + +```text +< HTTP/1.1 302 Found +< Content-Type: text/html; charset=utf-8 +< Location: https://discord.gg/9yYtgA4HXz +< Date: Sun, 08 Sep 2024 14:28:11 GMT +< Content-Length: 52 +< +Found. +``` + +```sh +curl -v localhost:8080/google +``` + +```text +< HTTP/1.1 301 Moved Permanently +< Content-Type: text/html; charset=utf-8 +< Location: https://www.google.com +< Date: Mon, 09 Sep 2024 08:38:22 GMT +< Content-Length: 57 +< +Moved Permanently. +``` + +### 查看統計數據 + +Shorts 會在 `config/stats.json` 中記錄每個重新導向的訪問者數量和最後訪問時間。 + +```json +{ + "discord": { + "visitors": 1, + "last_visited": "2024-09-08T22:28:11.894270007+08:00" + }, + "google": { + "visitors": 1, + "last_visited": "2024-09-09T16:38:22.113075596+08:00" + } +} +``` + +## 部署 + +我們建議使用 Docker 部署 Shorts。 + +### Docker + +```sh +docker run -d -p 8080:8080 \ + -v $PWD/config:/config \ + ghcr.io/ntut-npc/shorts +``` + +### Docker Compose + +參見位於 [docs/compose.yaml](docs/compose.yaml) 的配置範例。 + +## 開發 + +本地開發 Shorts 的步驟: + +1. 再製這個倉庫: + + ```sh + git clone https://github.com/ntut-npc/shorts.git + cd shorts + ``` + +2. 安裝依賴: + + ```sh + go mod download + ``` + +3. 執行應用程式: + + ```sh + go run . + ``` + +伺服器會在 `http://localhost:8080` 啟動。 + +### 開發期間的即時重新載入 + +為了獲得更好的開發體驗,我們推薦使用 [gow](https://github.com/mitranim/gow),它會在原始碼更改時自動重啟程式。 + +記得根據[即時重新載入設定](#即時重新載入設定)部分建立並編輯你的 `config/redirects.toml` 文件來設定重新導向。 diff --git a/docs/compose.yaml b/docs/compose.yaml index 2dae038..55c164a 100644 --- a/docs/compose.yaml +++ b/docs/compose.yaml @@ -1,8 +1,8 @@ services: shorts: - build: . + image: ghcr.io/ntut-npc/shorts container_name: shorts ports: - - "8080:80" + - "8080:8080" volumes: - ./config:/config diff --git a/docs/shorts.png b/docs/shorts.png deleted file mode 100644 index 829a363..0000000 Binary files a/docs/shorts.png and /dev/null differ diff --git a/docs/shorts.svg b/docs/shorts.svg new file mode 100644 index 0000000..fb34666 --- /dev/null +++ b/docs/shorts.svg @@ -0,0 +1 @@ + \ No newline at end of file