Skip to content

A simple web app built with Go, Echo, SQLite, and HTMX

Notifications You must be signed in to change notification settings

gpspake/simple-web-app

Repository files navigation

Simple Web App

A web application built with Go, Echo, SQLite, and HTMX. This app demonstrates basic routing, pagination, and full text search.

Demo: https://simple-web-app.georgespake.com


Features

  • Releases Management: View a paginated, searchable list of music releases with details like release year and associated artists.
  • Full Text Search: Uses the FTS5 sqlite extension with trigram tokenization.
  • Templating: Uses Go's html/template package for rendering HTML pages.
  • In-Memory Testing: Comprehensive test coverage with an in-memory SQLite database.

Tech Stack


Prerequisites

  • Go 1.20 or later
  • SQLite installed locally (for development)
  • Docker (optional, for containerized deployment)

Getting Started

1. Clone the Repository

git clone https://github.com/gpspake/simple-web-app
cd simple-web-app

2. Install Dependencies

go mod tidy

3. Run the App

go run -tags "sqlite_fts5" .

4. Visit the site

Navigate to localhost:8086 in a web browser.


Local development

With Air

Use Air to auto reload when files are changed.

1. Install Air

Make sure $GOPATH/bin is in your Path

go install github.com/air-verse/air@latest

2. Run the app using Air

air -c .air.toml

With Docker

You can also run the app with docker.

docker build -t simple-web-app .
docker run -p 8086:8086 simple-web-app

Or you can run

./start.sh

Deployment

This app is configured to deploy to a Digital Ocean using github actions.

Note: This section provides a general overview but it's not a comprehensive deployment guide. Some additional server configuration may be required.

  1. On the Droplet: Create a user for deployment and grant the user access to docker.
    sudo adduser deploy
    sudo usermod -aG docker deploy
    
  2. Switch to the user and add the public key to the user's authorized keys
    sudo su - deploy
    mkdir -p ~/.ssh
    chmod 700 ~/.ssh
    touch ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    echo "<YOUR_PUBLIC_KEY_CONTENT>" >> ~/.ssh/authorized_keys
    
  3. On Github: Go to your repository's Settings > Secrets and variables > Actions and add the following secrets:
    DIGITALOCEAN_IP: The IP address of your droplet.
    SSH_USERNAME: Your SSH username on the droplet.
    SSH_PRIVATE_KEY: Your private SSH key for authentication.
    
  4. Run the action. The deploy workflow is configured to run on push to main.
  5. Verify the container is running:
    docker ps
    CONTAINER ID   IMAGE                   COMMAND   CREATED         STATUS         PORTS                                                   NAMES
    19282e9c5697   simple-web-app:latest   "./app"   3 minutes ago   Up 3 minutes   8080/tcp, 0.0.0.0:8080->8086/tcp, [::]:8080->8086/tcp   simple-web-app
    
  6. Serve the app. Example using Caddy:
    simple-web-app.georgespake.com {
        reverse_proxy 127.0.0.1:8080
    
        tls {
                dns digitalocean {env.DO_AUTH_TOKEN}
        }
    
        log {
                output file /var/log/caddy/access.log
                format json
        }
    }
    

Other Stuff

To learn more about how this project was built, check out the commits. Each change is committed with a descriptive message and gitmoji

The purpose of this project was to learn more about the stack so some of it was new to me. If I got something wrong, let me know or submit a PR.

I might abandon this but I hope to keep it updated as a starter kit for other projects.

About

A simple web app built with Go, Echo, SQLite, and HTMX

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published