mirror of
https://github.com/TwiN/gatus.git
synced 2026-04-09 03:39:08 +00:00
4.6 KiB
4.6 KiB
AGENTS.md
Guidance for AI coding agents working in this repository.
Commands
make install— Build thegatusbinarymake run— Run in dev mode (uses./config.yaml)make test— Run all Go tests with coveragemake clean— Remove built binarymake frontend-install— Install frontend npm dependenciesmake frontend-build— Build the Vue.js frontend (must run after anyweb/changes)make frontend-dev— Start the Vue dev server
Key Rules
- Vendored dependencies: After adding/updating a Go dependency, run
go mod tidy && go mod vendor - Frontend build artifacts:
web/static/is generated bymake frontend-buildand embedded into the Go binary at compile time via//go:embed. Never edit files inweb/static/directly - Config validation order: In
config/config.goparseAndValidateConfigBytes,ValidateAlertingConfigmust run beforeValidateEndpointsConfigbecause provider default alerts must be parsed before endpoint defaults are set - Invalid configs panic at startup — validation errors are fatal, not graceful
- Hot-reload:
main.gowatches the config file and re-runs the full stop → save → load → init → start cycle. New startup logic must account for this
Environment Variables
GATUS_CONFIG_PATH— Config file path (default:config/config.yaml); can be a directory of YAML files (deep-merged)GATUS_LOG_LEVEL—DEBUG,INFO,WARN,ERRORENVIRONMENT=dev— Enables CORS for frontend dev onlocalhost:8081
Project Structure
main.go— Entry point; loads config, initializes storage, starts watchdog + API serverconfig/— Central config struct (config.go) and sub-packages per config section (each withValidateAndSetDefaults())alerting/— Alerting config (config.go), alert types (alert/type.go), and one sub-package per provider underprovider/api/— Fiber-based HTTP API routes and SPA servingwatchdog/— Monitoring loop; spawns a goroutine per endpoint with semaphore-based concurrency controlclient/— HTTP/gRPC client used for health checksstorage/store/— Storage abstraction withmemory/,sql/(SQLite + PostgreSQL) implementationssecurity/— Authentication (basic + OIDC) and security middlewareweb/app/— Vue 3 frontend source; builds toweb/static/(embedded into the Go binary)vendor/— Vendored Go dependencies (committed to repo)
Common Changes
Adding an Alerting Provider
Use alerting/provider/slack/ as the reference implementation. Every new provider touches 6 locations:
- Create provider package —
alerting/provider/{name}/{name}.go+{name}_test.goConfigstruct withValidate()andMerge(*Config)methodsAlertProviderstruct withDefaultConfig(yaml inline),DefaultAlert *alert.Alert,Overrides []Override- Use
client.GetHTTPClient(nil)(nothttp.DefaultClient), alwaysdefer response.Body.Close()
- Register type — Add
Type{Name} Type = "{name}"inalerting/alert/type.go - Add to config struct — Add field to
alerting.Configinalerting/config.go; the YAML tag must exactly match thealert.Typestring (reflection-based lookup viaGetAlertingProviderByAlertType) - Add compile-time checks — Both
_ AlertProvider = (*pkg.AlertProvider)(nil)and_ Config[pkg.Config] = (*pkg.Config)(nil)inalerting/provider/provider.go - Register in validation — Add the type to the
alertTypesslice inconfig/config.goValidateAlertingConfig - Document — Add to README.md in alphabetical order
Adding a Config Section
- Create package in
config/with struct +ValidateAndSetDefaults()method - Add field to
Configstruct inconfig/config.go - Add
Validate*call inparseAndValidateConfigBytes— respect ordering constraints (see comments in that function)
Frontend
- Vue 3 Composition API (
<script setup>) + Tailwind CSS - Props-based data flow — do not use provide/inject
- All components must include
dark:prefixed Tailwind classes for dark mode window.configcontains server-injected UI settings (Go template placeholders)
API Routes (api/api.go)
- Unprotected routes are registered before
ApplySecurityMiddleware - Protected routes are registered after — placement order matters
Testing
- Config structs should have
*_test.gofiles - Use
t.Parallel()where appropriate - API tests spin up test servers (see existing
*_test.goinapi/)
Commits & PRs
When creating a commit or PR as an agent, state that it was made by an agent and include your model name and version.