A service-oriented log viewer built with Go, Templ, Tailwind, and HTMX (GoTTH stack). This project demonstrates the transformation of a React-based SPA into a server-side rendered application with real-time updates.
- 🔒 Secure authentication with scrypt-based password hashing
- 🔄 Real-time log monitoring with automatic updates
- 🔍 Advanced filtering capabilities (by program, log level, and search)
- 🎨 Clean, responsive UI with Catppuccin Mocha theme
- 📱 Mobile-friendly design
- 🚀 Fast server-side rendering with partial updates
- 💾 Efficient log parsing and caching
- 🌐 Almost Zero JavaScript framework dependencies
- 🔐 HTTPS support out of the box
The application follows a clean, service-oriented architecture pattern:
internal/
├── auth/ # Authentication system
├── filters/ # Log filtering logic
├── handlers/ # HTTP request handlers
├── services/ # Core business logic
├── shared/ # Shared utilities
├── types/ # Type definitions
└── view/ # UI components (Templ)
Key architectural decisions:
-
Security First:
- Secure authentication with scrypt hashing
- HTTPS enforcement
- Secure session management
-
Separation of Concerns:
AuthService
: Handles authentication and session managementLogService
: Handles log file reading, parsing, and cachingFilterService
: Manages log filtering and sortingHandlerService
: Coordinates HTTP requests and responses
-
Real-time Updates:
- Uses HTMX for seamless partial page updates
- Polling mechanism with optimized cache layer
- Server-side filtering to reduce network load
-
Component-Based UI:
- Templ components for server-side rendering
- Tailwind CSS for styling
- HTMX for interactive updates
- Go 1.21+
- TLS certificate and key for HTTPS
templ
CLI tool
- Clone the repository:
git clone https://github.com/yourusername/gotth-logviewer.git
cd gotth-logviewer
- Install dependencies:
go mod download
- Create environment file:
cat > .env << EOL
LISTEN_ADDR=":5173" # Editable your own
LOG_PATH="/path/to/your/app.log"
CERT_FILE="/path/to/your/server.crt"
KEY_FILE="/path/to/your/server.key"
ALLOWED_ORIGINS="*" # Your own DDNS or IP
CRED_HASH="your_generated_hash_here" # Generate using the provided tool
EOL
- Generate credential hash:
go run cmd/hashgen/main.go username your_passphrase
Copy function from internal/auth/store.go, and make tempmain in other directory. Copy the output hash to your .env file's CRED_HASH variable.
- Build CSS:
make css-once
Start the development server with live reload:
make dev
This command runs:
- Templ template compiler with auto-reload
- Go server with hot reload (using Air)
- CSS compiler
- Create a service file:
sudo nano /etc/systemd/system/gotthlogviewer.service
- Add the following content:
[Unit]
Description=GoTTH Log Viewer
After=network.target
[Service]
Type=simple
User=your_user
Group=your_group
WorkingDirectory=/path/to/gotthlogviewer
EnvironmentFile=/path/to/gotthlogviewer/.env
ExecStart=/path/to/gotthlogviewer/gotthlogviewer
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
- Set appropriate permissions:
sudo chmod 644 /etc/systemd/system/gotthlogviewer.service
sudo chmod 600 /path/to/gotthlogviewer/.env
- Start and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable gotthlogviewer
sudo systemctl start gotthlogviewer
Secure authentication implementation:
type Credential struct {
Username string
Hash []byte // scrypt hash of username_passphrase
}
Features:
- Scrypt-based password hashing
- Secure session management
- HTTPS enforcement
- Protection against timing attacks
The core service managing log operations:
type LogService struct {
filepath string
cache []types.LogEntry
lastRead time.Time
lastModTime time.Time
mu sync.RWMutex
onChange func([]types.LogEntry)
}
Features:
- Efficient log parsing and caching
- File change detection
- Thread-safe operations
- Change notification system
Implements flexible filtering logic:
type LogFilters struct {
Program string
Level string
Search string
}
Supports:
- Program-based filtering
- Log level filtering
- Full-text search
- Combined filters
- Always use HTTPS in production
- Store the .env file securely with restricted permissions (chmod 600)
- Keep your credential hash secure and never commit it to version control
- Regularly update your TLS certificates
- Consider implementing rate limiting for the login endpoint in production
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Templ for the templating system
- HTMX for the interactive capabilities
- Tailwind CSS for styling
- Catppuccin for the color scheme