Development Setup¶
Set up your local environment for developing external-dns-unifios-webhook.
Prerequisites¶
- Go 1.25 or later
- Git
- Access to a UniFi controller (for integration testing)
- Podman or Docker (for container builds)
Clone Repository¶
git clone https://github.com/lexfrei/external-dns-unifios-webhook.git
cd external-dns-unifios-webhook
Install Dependencies¶
Build¶
Binary¶
With Version Info¶
go build -ldflags "-s -w -X main.Version=dev -X main.Gitsha=$(git rev-parse HEAD)" \
-trimpath -o webhook ./cmd/webhook
Run Locally¶
Set required environment variables:
export WEBHOOK_UNIFI_HOST="https://192.168.1.1"
export WEBHOOK_UNIFI_API_KEY="your-api-key"
export WEBHOOK_LOGGING_LEVEL="debug"
Run the webhook:
The webhook will listen on:
localhost:8888- Webhook API0.0.0.0:8080- Health/metrics endpoints
Testing¶
Run All Tests¶
With Race Detection¶
With Coverage¶
Specific Package¶
Linting¶
Install golangci-lint¶
Run Linter¶
Auto-fix¶
Container Build¶
Build Image¶
Run Container¶
podman run --rm \
--env WEBHOOK_UNIFI_HOST="https://192.168.1.1" \
--env WEBHOOK_UNIFI_API_KEY="your-api-key" \
--publish 8888:8888 \
--publish 8080:8080 \
external-dns-unifios-webhook:local
IDE Setup¶
VS Code¶
Recommended extensions:
- Go (golang.go)
- EditorConfig for VS Code
- YAML
Settings (.vscode/settings.json):
{
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast"],
"go.testFlags": ["-race"],
"editor.formatOnSave": true
}
GoLand¶
- Enable Go modules integration
- Set Go to use golangci-lint as external linter
- Enable "Format on save"
Environment Variables for Development¶
| Variable | Description | Example |
|---|---|---|
WEBHOOK_UNIFI_HOST | UniFi controller URL | https://192.168.1.1 |
WEBHOOK_UNIFI_API_KEY | API key | abc123... |
WEBHOOK_LOGGING_LEVEL | Log level | debug |
WEBHOOK_LOGGING_FORMAT | Log format | text |
Debugging¶
Enable pprof¶
Access pprof at http://localhost:6060/debug/pprof/