mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-20 16:23:53 +01:00
- Added information about the loading page (HTML + JS + CSS) and the SSE endpoint for wake events. - Clarified the health monitor implementation and readiness tracking in the architecture overview. - Correct state machine syntax.
3.5 KiB
3.5 KiB
alwaysApply: true
Cursor Rules
Project Overview
GoDoxy is a lightweight reverse proxy with WebUI written in Go. It automatically configures routes for Docker containers using labels and provides SSL certificate management, access control, and monitoring capabilities.
Development Commands
You should not run any commands to build or run the project.
Documentation
If README.md exists in the package:
- Read it to understand what the package does and how it works.
- Update it with the changes you made (if any).
Update the roort README.md if relevant.
Architecture
Core Components
-
Main Entry Point (
cmd/main.go)- Initializes configuration and logging
- Starts the proxy server and WebUI
-
Internal Packages (
internal/)config/- Configuration management with YAML filesroute/- HTTP routing and middleware managementdocker/- Docker container integration and auto-discoveryautocert/- SSL certificate management with Let's Encryptacl/- Access control lists (IP/CIDR, country, timezone)api/- REST API server with Swagger documentationhomepage/- WebUI dashboard and configuration interfacemetrics/- System metrics and uptime monitoringidlewatcher/- Container idle detection and power managementwatcher/- File and container state watchers
-
Sub-projects
agent/- System agent for monitoring containerssocket-proxy/- Docker socket proxy
Key Patterns
- Task Management: Use
internal/task/task.gofor managing object lifetimes and background operations - Concurrent Maps: Use
github.com/puzpuzpuz/xsync/v4instead of maps with mutexes - Error Handling: Use
pkg/gperrfor nested errors with subjects - Configuration: YAML-based configuration in
config/directory
Go Guidelines (from .cursor/rules/go.mdc)
- Use builtin
minandmaxfunctions instead of custom helpers - Prefer range-over-integer syntax (
for i := range 10) over traditional loops - Use
xsync/v4for concurrent maps instead of map+mutex - Beware of variable shadowing when making edits
- Use
internal/task/task.gofor lifetime management:task.RootTask()for background operationsparent.Subtask()for nested tasksOnFinished()andOnCancel()callbacks for cleanup
- Use
pkg/gperrfor complex error scenarios:gperr.Multiline()for multiple operation attemptsgperr.NewBuilder()for collecting multiple errorsgperr.NewGroup() + group.Go()for collecting errors of multiple concurrent operationsgperr.New().Subject()for errors with subjects
Configuration Structure
config/config.yml- Main configurationconfig/middlewares/- HTTP middleware configurationsconfig/*.yml- Provider and service configurations.env- Environment variables for ports and settings
Testing
Tests are located in internal/ packages and can be run with:
make test- Run all internal package tests- Individual package tests:
go test ./internal/config/... - You MUST use
-ldflags="-checklinkname=0"otherwise compiler will complain - prefer
testify/requireoverexpect
Docker Integration
GoDoxy integrates with Docker by:
- Listing all containers and reading their labels
- Creating routes based on
proxy.aliaseslabel or container name - Watching for container/config changes and updating automatically
- Supporting both Docker and Podman runtimes