Skip to content
/ stn Public

πŸ”— Yet another URL shortener web app, written in Go with minimal dependencies.. no framework, no ORM.

License

Notifications You must be signed in to change notification settings

nadiannis/stn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Stn logo

Stn

Shorten your links, share it easily


Table of Contents

Description

^ back to top ^

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.

Live Demo

^ back to top ^

Check out the web app here:

Main Features

^ back to top ^

Shorten a Long Link

Shorten a long link on home page

Shorten a long link

Redirect the Short Link

Redirect the short link

View Engagements

Total engagements

Manage Links

Edit, view details, & delete a link

Routes

^ back to top ^

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.

Database Schema

^ back to top ^

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
    }
Loading

Tech Stack

^ back to top ^

Run Locally

^ back to top ^

Development

  • 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

Format & Check the Code

Run this command to tidy the dependencies, format the code, & vet the code.

make audit

Contributing

^ back to top ^

You can contribute to this project by creating an issue or pull request.

License

^ back to top ^

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸ”— Yet another URL shortener web app, written in Go with minimal dependencies.. no framework, no ORM.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published