Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改善 README,新增中文文件 #3

Merged
merged 13 commits into from
Sep 15, 2024
119 changes: 79 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<p align="center">
<img src="docs/shorts.png" alt="Shorts Logo" align="center" width="100" height="100">
<img src="docs/shorts.svg" alt="Shorts Logo" align="center" width="128" height="128">
</p>

<h1 align="center">短褲</h1>
<h1 align="center">短褲 Shorts</h1>

<p align="center">一個極簡的短網址伺服器</p>
<p align="center">A lightweight URL shortener built with Go</p>

## 用
<p align="center"><a href="README.zh.md">中文版本</a></p>

1. 設
## Features

### Hot-Reloading Configuration

Edit the `config/redirects.toml` file and Shorts will automatically reload the configuration.

```toml
# config/redirects.toml
Expand All @@ -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

<a href="https://discord.gg/9yYtgA4HXz">Found</a>..
< 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
<
<a href="https://discord.gg/9yYtgA4HXz">Found</a>.
```

```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

<a href="https://play.google.com/store/apps/details?id=club.ntut.npc.tat">Moved Permanently</a>.
< 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
<
<a href="https://www.google.com">Moved Permanently</a>.
```

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.
121 changes: 121 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<p align="center">
<img src="docs/shorts.svg" alt="Shorts Logo" align="center" width="128" height="128">
</p>

<h1 align="center">短褲 Shorts</h1>

<p align="center">一個使用 Go 語言製作的輕量短網址服務</p>

## 功能

### 即時重新載入設定

編輯 `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
<
<a href="https://discord.gg/9yYtgA4HXz">Found</a>.
```

```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
<
<a href="https://www.google.com">Moved Permanently</a>.
```

### 查看統計數據

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` 文件來設定重新導向。
4 changes: 2 additions & 2 deletions docs/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
services:
shorts:
build: .
image: ghcr.io/ntut-npc/shorts
container_name: shorts
ports:
- "8080:80"
- "8080:8080"
volumes:
- ./config:/config
Binary file removed docs/shorts.png
Binary file not shown.
1 change: 1 addition & 0 deletions docs/shorts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.