Skip to content

Commit 77ce32a

Browse files
committed
docs: add comprehensive @moduledoc to all internal modules
- Add detailed documentation for Caddy.Admin.Request (HTTP client implementation) - Add documentation for Caddy.Admin.Api (high-level API interface) - Add documentation for Caddy.Admin (health check GenServer) - Add documentation for Caddy.Logger.Buffer (log buffering) - Add documentation for Caddy.Logger.Store (log storage) - Add documentation for Caddy.Application (OTP application) All modules now have proper @moduledoc entries explaining their: - Purpose and responsibility - Key features - Usage examples (where applicable) - Implementation details This completes Phase 3 of the optimization plan.
1 parent ecf3489 commit 77ce32a

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

lib/caddy/admin.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
defmodule Caddy.Admin do
2-
@moduledoc false
2+
@moduledoc """
3+
GenServer that periodically checks Caddy server health.
4+
5+
This module runs as a background process that checks the Caddy server
6+
status every 15 seconds and logs any connection issues.
7+
"""
38
require Logger
49

510
use GenServer

lib/caddy/admin/api.ex

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
defmodule Caddy.Admin.Api do
2-
@moduledoc false
2+
@moduledoc """
3+
High-level interface to the Caddy Admin API.
4+
5+
Provides a convenient Elixir API for interacting with Caddy's admin endpoints,
6+
including configuration management, server control, and health monitoring.
7+
8+
## Features
9+
10+
- Configuration loading and reloading
11+
- Caddyfile adaptation (convert to JSON)
12+
- Health checks and server information
13+
- Telemetry integration for monitoring
14+
- Mock support for testing via RequestBehaviour
15+
16+
## Examples
17+
18+
# Get current configuration
19+
{:ok, config} = Caddy.Admin.Api.get_config()
20+
21+
# Load new configuration
22+
Caddy.Admin.Api.load(new_config)
23+
24+
# Adapt Caddyfile to JSON
25+
{:ok, json_config} = Caddy.Admin.Api.adapt(caddyfile_content)
26+
27+
# Check server health
28+
{:ok, status} = Caddy.Admin.Api.health_check()
29+
"""
330
require Logger
431

532
defp request_module, do: Application.get_env(:caddy, :request_module, Caddy.Admin.Request)

lib/caddy/admin/request.ex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
defmodule Caddy.Admin.Request do
2-
@moduledoc false
2+
@moduledoc """
3+
Low-level HTTP client for Caddy Admin API over Unix domain sockets.
4+
5+
This module provides direct HTTP communication with the Caddy admin API
6+
using Unix domain sockets. It implements the RequestBehaviour and handles
7+
GET, POST, PUT, PATCH, and DELETE operations.
8+
9+
## Implementation Details
10+
11+
- Uses `:gen_tcp` for Unix socket communication
12+
- Parses HTTP responses with `:http_bin` packet mode
13+
- Automatically decodes JSON responses
14+
- Returns structured response with status, headers, and body
15+
"""
316
@behaviour Caddy.Admin.RequestBehaviour
417

518
alias Caddy.Admin.Request

lib/caddy/application.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
defmodule Caddy.Application do
2-
@moduledoc false
2+
@moduledoc """
3+
OTP Application for Caddy reverse proxy management.
4+
5+
Starts the main Caddy supervisor tree when the application starts.
6+
Note: Only starts in non-test environments (see mix.exs).
7+
"""
38

49
use Application
510

lib/caddy/logger/buffer.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
defmodule Caddy.Logger.Buffer do
2-
@moduledoc false
2+
@moduledoc """
3+
GenServer that buffers log messages before writing to storage.
4+
5+
Collects log output from the Caddy server process and buffers
6+
messages until complete lines are received. When newlines are
7+
detected, complete log lines are flushed to the Logger.Store.
8+
"""
39

410
use GenServer
511
require Logger

lib/caddy/logger/store.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
defmodule Caddy.Logger.Store do
2-
@moduledoc false
2+
@moduledoc """
3+
GenServer that stores Caddy server log history.
4+
5+
Maintains a rolling buffer of up to 50,000 log lines from the Caddy
6+
server. Provides access to recent logs via the `tail/1` function.
7+
"""
38

49
require Logger
510

0 commit comments

Comments
 (0)