A Go short URL service.
This project uses Podman as the container engine, but any OCI-compatible container engine should work.
Docker support is included.
Taskfile is introduced as an alternative to Makefile. Instead of typing a cluster of long long commands, you can use
task upto compose up containerstask migrateto create tables, insert values from the SQL files under sql/task runto run servertask databaseto connect to the interactive shell of the database in the containertask cacheto connect to the interactive shell of the cache in the containertask downto shut down containerstask cleanto shut down containers and remove all data (be careful!)
Taskfile uses the YAML format, and you will find it familiar if you have read GitHub Actions workflows before.
The language we Gophers love. The Go version of this project is 1.26.2.
Note
This project adopts the go-zero framework. To generate code from API files (*.api), please follow the official guide. You don't need to install go-zero toolchain if you're not developing new features.
To run the short url server, just follow the three steps:
- Compose up containers. Middlewares used in this project are defined in docker-compose.yml. If you're using Podman or Docker, you can just run
task upto do so. - Migrate database. Create database and tables defined in the sql/ directory.
task migrateis the shortcut. - Start the server. Run the server entrypoint under cmd/server.
task runis the shortcut.
flowchart LR
A["POST /shorten HTTP/1.1<br><br>{ "longUrl": "..." }"]
R{Is URL reachable?}
D1[Refuse shortening]
A --> R
R --> |No| D1
R --> |Yes| L
L{Is shortened before?}
D2[Refuse shortening]
L --> |Yes| D2
L --> |No| S
S{Is already short URL?}
D3[Refuse shortening]
S --> |Yes| D3
S --> |No| G
G[Generate short URL]
B[Store into database]
F[Insert into Bloom Filter]
G --> B
B --> F
flowchart LR
A["GET /3v1Lx7 HTTP/1.1"]
F{Exists in Bloom Filter?}
A --> F
N1[404 not found]
F --> |No| N1
F --> |Yes| C
C{Is cached?}
R1[Redirect to long URL]
C --> |Yes| R1
C --> |No| D
D{Exists in database?}
U[Update cache]
N2[404 not found]
D --> |Yes| U --> R2[Redirect to long URL]
D --> |No| N2
Copyright 2026 Open Portfolios Authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.