Coder Social home page Coder Social logo

danielmichaels / tars.run Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 2.0 233 KB

A simple URL shortener written in Go.

Home Page: https://tars.run

License: Apache License 2.0

Shell 2.15% Go 52.49% JavaScript 3.91% CSS 0.12% Dockerfile 4.42% templ 36.92%
golang litestream

tars.run's Introduction

Tars.Run

A simple short link application backend written in Go.

Demo site: https://tars.run

Note

This site may have downtime and loss of data is possible. I recommend self-hosting this application if you require durability.

Installation

The prod version runs in a single docker container with a dependency on Litestream.

In order to use this project's Dockerfile, you'll need to understand how to use Litestream and fill out the appropriate environment variables.

Environment variables can be found in .env.example.

# create a .env
cp .env.example .env
# or feel free to use any other method to inject the required environment variables into your shell.

The application uses goose to perform database migrations. To bootstrap the database, you'll need to install goose and create a SQLite database file.

go get github.com/pressly/goose/v3/cmd/goose
mkdir -p data
touch data/shorty.db.up
task db:migration:up

In development, the application can be started using air. Simply run the air command and a hot-reloading webserver will be started. The migrations must be applied in order to create the tables.

# development
task dev

Note: hot-reloading requires air and templ

There is a Taskfile with a large number of commands.

Web version

How it works

This version of the application is self-contained using Go templates and embedded files. Adding new links is done via a POST request to the v1/links endpoint which saves it to the database and renders it in the template. All other endpoints are GET requests and accessible via the web pages / and /{hash}/analytics.

When developing, if adding new Tailwind classes you may be required to re-run the Tailwind compiler. To do that just run task tailwind which will output a minified CSS file named theme.css in assets/static/css. This is used in the assets/static/view/layout/base.templ file. Both Alpine.js and Tailwind are self-contained in this binary for portability and to reduce network calls.

All templates use templ as it provides type safety over Go's standard library template package.

Endpoints

Method URL Handler Action Authentication
GET / handleHome Retrieves all links False
GET /:hash handleRedirect Retrieves a single link False
POST /v1/links handleCreateLink Creates a new link False

Self Hosting

This application is designed to be deployed as a container.

The following environment variables are required to run this if using Litestream.

LITESTREAM_SECRET_ACCESS_KEY=
LITESTREAM_ACCESS_KEY_ID=
DB_PATH=./data/data.db
LITESTREAM_BUCKET=
LITESTREAM_ENDPOINT=
LITESTREAM_RETENTION=72h
DB_SYNC_INTERVAL=60s
LITESTREAM_DB_NAME=

Refer to .env.example for more configuration options such as Social Media accounts and application name.

Stack

Development

You will require the following tools:

License

Licenced under Apache 2.0, see LICENSE.

tars.run's People

Contributors

danielmichaels avatar mtlynch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mtlynch tanvirraj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.