Skip to content

Go web application showcasing server-side rendering with Go and real-time UI updates using HTMX and Go Templates

License

Notifications You must be signed in to change notification settings

madalinpopa/go-htmx-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go HTMX Demo

CRUD application built with Go and HTMX for managing a collection of dogs. Use server-side rendering and HTMX for real-time updates without JavaScript.

Features

  • Create, read, update, delete dogs
  • Real-time UI updates via HTMX
  • Server-side rendering with Go templates
  • Thread-safe operations with atomic integers
  • Tailwind CSS styling

Requirements

  • Go 1.23.4+
  • air (live reload)
  • Tailwind CSS CLI

Setup

  1. Install required tools:

    # Install air for live reload
    go install github.com/air-verse/air@latest
    
    # Install Tailwind CSS CLI
    # macOS
    brew install tailwindcss
    
    # Windows (scoop)
    scoop install tailwindcss
    
    # Linux
    curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64
    chmod +x tailwindcss-linux-x64
    sudo mv tailwindcss-linux-x64 /usr/local/bin/tailwindcss
  2. Get the code and dependencies:

    git clone https://github.com/username/go-htmx-demo.git
    cd go-htmx-demo
    just update   # Updates Go dependencies

Development Commands

# Update Go dependencies
just update

# Start development server with hot reload
just run

The just run command:

  • Start Go server at http://localhost:4000
  • Watches for file changes and rebuilds
  • Auto-recompiles Tailwind CSS
  • Handles cleanup on exit

Project Structure

.
├── cmd/web/             # Main application code
│   ├── handlers.go      # HTTP request handlers
│   ├── main.go          # Application entry point
│   ├── models.go        # Data structures and logic
│   └── routes.go        # URL routing configuration
├── ui/                  # Frontend assets
│   ├── assets/          # Source files
│   │   └── input.css    # Source Tailwind CSS
│   ├── embed.go         # Static file embedding
│   ├── html/            # Go templates
│   │   ├── base.tmpl    # Base layout
│   │   ├── pages/       # Page templates
│   │   └── partials/    # Reusable components
│   └── static/          # Compiled assets
│       ├── css/         # Compiled CSS
│       └── js/          # JavaScript libraries
├── justfile             # Development commands
└── tailwind.config.js   # Tailwind CSS config

Key Files

  • cmd/web/models.go: Dog data structure and operations
  • cmd/web/handlers.go: HTTP handlers for CRUD operations
  • cmd/web/routes.go: URL routing setup
  • ui/html/pages/dogs.tmpl: Main dogs page template with HTMX partials
  • justfile: Development automation commands

License

MIT License - See LICENSE file for details

About

Go web application showcasing server-side rendering with Go and real-time UI updates using HTMX and Go Templates

Topics

Resources

License

Stars

Watchers

Forks