- Description
- Live Demo
- Main Features
- Routes
- Database Schema
- Tech Stack
- Run Locally
- Contributing
- License
Stn is a web-based app for shortening long links & managing them in one place. It is written in Go with minimal dependencies. In addition to making link sharing easier, I also created this to learn more about web server & its interactions with client & database.
Check out the web app here:
Method | Pattern | Description |
---|---|---|
GET | /users/signup | Show the sign up page. |
POST | /users/signup | Register a user. |
GET | /users/login | Show the login page. |
POST | /users/login | Authenticate a user. |
POST | /users/logout | Log out a user from the app. |
GET | / | Show the home page. |
GET | /:backhalf | Redirect to the original link. |
GET | /links/list | Show links created by a user. |
GET | /links/create | Show the page to shorten a long link. |
POST | /links/create | Shorten a long link. |
GET | /links/:id | Show the details of a link. |
GET | /links/:id/edit | Show the page to edit a link. |
PUT | /links/:id/edit | Edit a link. |
DELETE | /links/:id | Delete a link. |
erDiagram
USER |o--o{ LINK : "shortens"
USER {
string id PK
string email
string password
datetime date_joined
}
LINK {
string id PK
string url
string back_half
int engagements
string user_id FK
datetime created_at
datetime updated_at
}
- Language: Go 1.22
- DBMS: MySQL
- Database Migration: migrate
- Session Management: SCS
- UI: HTML, CSS, JavaScript
-
Make sure you have Go 1.22, MySQL, migrate, & Make installed on your computer. Run these commands to check whether the tools are already installed. The terminal will output the version number if it is installed.
go version
mysql --version
migrate -version
make --version
-
Connect to the MySQL server by providing a user name & password.
mysql -u root -p
Then create a database. You can name it as
stn
.CREATE DATABASE stn CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-
Clone the repo.
git clone https://github.com/nadiannis/stn.git
cd stn
-
Make a copy of
.env.example
file & rename it to.env
.cp .env.example .env
Connect the app to the database by writing the information about the database you use in the
.env
file.# example DB_USER=stn DB_PASS=password DB_PROTO=tcp DB_HOST=localhost DB_PORT=3306 DB_NAME=stn
-
Install the dependencies.
go mod tidy
-
Apply migrations.
make db/migrations/up
-
Run the server. The web server will run on port 8080.
make run/web
Run this command to tidy the dependencies, format the code, & vet the code.
make audit
You can contribute to this project by creating an issue or pull request.
This project is licensed under the MIT License - see the LICENSE file for details.