Development Guidelines
Logging
Log Format Configuration
Set NTN_LOG_FORMAT environment variable to control output:
text(default): Human-readable format for developmentjson: Structured JSON for CI/CD and log aggregation
# JSON format for production/CI
NTN_LOG_FORMAT=json ./ntnsync sync
# Text format (default)
./ntnsync sync -v
Using slog
Always use the logger with context when available:
// Good
c.logger.DebugContext(ctx, "processing page", "page_id", pageID)
c.logger.InfoContext(ctx, "sync complete", "pages", count)
slog.DebugContext(ctx, "operation started")
// Avoid (when context is available)
c.logger.Debug("processing page", "page_id", pageID)
slog.Debug("operation started")
Using context-aware logging enables better tracing and correlation of log entries.
Code Organization
Main packages:
internal/cmd/- CLI command handlersinternal/notion/- Notion API client and typesinternal/sync/- Sync logic (crawler, converter, queue, state)internal/store/- Storage abstraction (git-backed filesystem)internal/webhook/- Webhook server for real-time syncinternal/version/- Version information
Testing
go test ./...
Building
go build -o ntnsync .
With version information:
VERSION=$(git describe --tags --always)
COMMIT=$(git rev-parse --short HEAD)
GIT_TIME=$(TZ=UTC git log -1 --format=%cd --date=format-local:%Y-%m-%dT%H:%M:%SZ)
go build -ldflags "-X 'github.com/fclairamb/ntnsync/internal/version.Version=$VERSION' \
-X 'github.com/fclairamb/ntnsync/internal/version.Commit=$COMMIT' \
-X 'github.com/fclairamb/ntnsync/internal/version.GitTime=$GIT_TIME'" \
-o ntnsync .
Docker
Build the Docker image:
docker build -t ntnsync .
Run with Docker:
docker run --rm \
-e NOTION_TOKEN=secret_xxx \
-v $(pwd)/notion:/data \
ntnsync sync
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
go test ./... - Submit a pull request
PR titles should follow Conventional Commits:
feat: add new featurefix: fix bugdocs: update documentationchore: maintenance task