Skip to content

Commit cdec63c

Browse files
committed
Documentation and mod tidy
1 parent 1b95e42 commit cdec63c

6 files changed

Lines changed: 260 additions & 49 deletions

File tree

README.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,19 @@ Modular is a package that provides a structured way to create modular applicatio
2727

2828
Modular comes with a rich ecosystem of pre-built modules that you can easily integrate into your applications:
2929

30-
| Module | Description | Documentation |
31-
|------------------------------------|------------------------------------------|-------------------------------------------------|
32-
| [chimux](./modules/chimux) | Chi router integration for Modular | [Documentation](./modules/chimux/README.md) |
33-
| [database](./modules/database) | Database connectivity and SQL operations | [Documentation](./modules/database/README.md) |
34-
| [httpclient](./modules/httpclient) | Configurable HTTP client with connection pooling, timeouts, and verbose logging | [Documentation](./modules/httpclient/README.md) |
35-
| [httpserver](./modules/httpserver) | HTTP/HTTPS server with TLS support, graceful shutdown, and configurable timeouts | [Documentation](./modules/httpserver/README.md) |
36-
| [jsonschema](./modules/jsonschema) | JSON Schema validation services | [Documentation](./modules/jsonschema/README.md) |
37-
| [letsencrypt](./modules/letsencrypt) | SSL/TLS certificate automation with Let's Encrypt | [Documentation](./modules/letsencrypt/README.md) |
38-
| [reverseproxy](./modules/reverseproxy) | Reverse proxy with routing capabilities | [Documentation](./modules/reverseproxy/README.md) |
39-
40-
### Core Modules
41-
- **[Auth](modules/auth/README.md)** - Comprehensive authentication with JWT, sessions, password hashing, and OAuth2/OIDC support
42-
- **[Cache](modules/cache/README.md)** - Multi-backend caching with Redis and in-memory support
43-
- **[Database](modules/database/README.md)** - Database connectivity and management with multiple driver support
44-
- **[Event Bus](modules/eventbus/README.md)** - Asynchronous event handling and pub/sub messaging
45-
46-
### Network & Communication
47-
- **[Chi Router (Chimux)](modules/chimux/README.md)** - HTTP routing with Chi router integration and middleware support
48-
- **[Reverse Proxy](modules/reverseproxy/README.md)** - Advanced reverse proxy with load balancing, circuit breaker, and health checks
49-
50-
### Utilities & Processing
51-
- **[JSON Schema](modules/jsonschema/README.md)** - JSON schema validation and processing
52-
- **[Scheduler](modules/scheduler/README.md)** - Job scheduling with cron expressions and worker pools
30+
| Module | Description | Configuration | Documentation |
31+
|------------------------------------|------------------------------------------|---------------|-----------------------------------------------|
32+
| [auth](./modules/auth) | Authentication and authorization with JWT, sessions, password hashing, and OAuth2/OIDC support | Yes | [Documentation](./modules/auth/README.md) |
33+
| [cache](./modules/cache) | Multi-backend caching with Redis and in-memory support | Yes | [Documentation](./modules/cache/README.md) |
34+
| [chimux](./modules/chimux) | Chi router integration with middleware support | Yes | [Documentation](./modules/chimux/README.md) |
35+
| [database](./modules/database) | Database connectivity and SQL operations with multiple driver support | Yes | [Documentation](./modules/database/README.md) |
36+
| [eventbus](./modules/eventbus) | Asynchronous event handling and pub/sub messaging | Yes | [Documentation](./modules/eventbus/README.md) |
37+
| [httpclient](./modules/httpclient) | Configurable HTTP client with connection pooling, timeouts, and verbose logging | Yes | [Documentation](./modules/httpclient/README.md) |
38+
| [httpserver](./modules/httpserver) | HTTP/HTTPS server with TLS support, graceful shutdown, and configurable timeouts | Yes | [Documentation](./modules/httpserver/README.md) |
39+
| [jsonschema](./modules/jsonschema) | JSON Schema validation services | No | [Documentation](./modules/jsonschema/README.md) |
40+
| [letsencrypt](./modules/letsencrypt) | SSL/TLS certificate automation with Let's Encrypt | Yes | [Documentation](./modules/letsencrypt/README.md) |
41+
| [reverseproxy](./modules/reverseproxy) | Reverse proxy with load balancing, circuit breaker, and health monitoring | Yes | [Documentation](./modules/reverseproxy/README.md) |
42+
| [scheduler](./modules/scheduler) | Job scheduling with cron expressions and worker pools | Yes | [Documentation](./modules/scheduler/README.md) |
5343

5444
Each module is designed to be:
5545
- **Plug-and-play**: Easy integration with minimal configuration

examples/advanced-logging/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module advanced-logging
33
go 1.24.2
44

55
require (
6-
github.com/GoCodeAlone/modular v1.2.5
6+
github.com/GoCodeAlone/modular v1.2.6
77
github.com/GoCodeAlone/modular/modules/chimux v0.0.0
88
github.com/GoCodeAlone/modular/modules/httpclient v0.0.0
99
github.com/GoCodeAlone/modular/modules/httpserver v0.0.0

examples/http-client/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module http-client
33
go 1.24.2
44

55
require (
6-
github.com/GoCodeAlone/modular v1.2.5
6+
github.com/GoCodeAlone/modular v1.2.6
77
github.com/GoCodeAlone/modular/modules/chimux v0.0.0
88
github.com/GoCodeAlone/modular/modules/httpclient v0.0.0
99
github.com/GoCodeAlone/modular/modules/httpserver v0.0.0

examples/reverse-proxy/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module reverse-proxy
33
go 1.24.2
44

55
require (
6-
github.com/GoCodeAlone/modular v1.2.5
6+
github.com/GoCodeAlone/modular v1.2.6
77
github.com/GoCodeAlone/modular/modules/chimux v0.0.0
88
github.com/GoCodeAlone/modular/modules/httpserver v0.0.0
99
github.com/GoCodeAlone/modular/modules/reverseproxy v0.0.0

modules/README.md

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,19 @@ This directory contains all the pre-built modules available in the Modular frame
66

77
## 📋 Module Directory
88

9-
| Module | Description | Configuration | Dependencies |
10-
|----------------------------|------------------------------------------|-----------------------------------------|----------------------------------------|
11-
| [chimux](./chimux) | Chi router integration for Modular | [Yes](./chimux/config.go) | - |
12-
| [database](./database) | Database connectivity with SQL operations | [Yes](./database/config.go) | - |
13-
| [httpclient](./httpclient) | Configurable HTTP client with connection pooling, timeouts, and verbose logging | [Yes](./httpclient/config.go) | - |
14-
| [httpserver](./httpserver) | HTTP/HTTPS server with TLS support, graceful shutdown, and configurable timeouts | [Yes](./httpserver/config.go) | - |
15-
| [jsonschema](./jsonschema) | Provides JSON Schema validation services | No | - |
16-
| [letsencrypt](./letsencrypt) | SSL/TLS certificate automation with Let's Encrypt | [Yes](./letsencrypt/config.go) | [httpserver](./httpserver) |
17-
| [reverseproxy](./reverseproxy) | Reverse proxy with routing capabilities | [Yes](./reverseproxy/config.go) | - |
18-
19-
### Core Modules
20-
- **[Auth](auth/README.md)** - Authentication and authorization with JWT, sessions, password hashing, and OAuth2/OIDC support
21-
- **[Cache](cache/README.md)** - Multi-backend caching solution with Redis and in-memory implementations
22-
- **[Database](database/README.md)** - Database connectivity and management with support for multiple drivers
23-
- **[Event Bus](eventbus/README.md)** - Asynchronous event handling and pub/sub messaging system
24-
25-
### Network & Communication
26-
- **[Chi Router (Chimux)](chimux/README.md)** - HTTP routing with Chi router integration and comprehensive middleware support
27-
- **[Reverse Proxy](reverseproxy/README.md)** - Advanced reverse proxy with load balancing, circuit breaker, and health monitoring
28-
29-
### Utilities & Processing
30-
- **[JSON Schema](jsonschema/README.md)** - JSON schema validation and data processing capabilities
31-
- **[Scheduler](scheduler/README.md)** - Job scheduling system with cron expressions and worker pool management
9+
| Module | Description | Configuration | Dependencies |
10+
|----------------------------|------------------------------------------|---------------|----------------------------------------|
11+
| [auth](./auth) | Authentication and authorization with JWT, sessions, password hashing, and OAuth2/OIDC support | [Yes](./auth/config.go) | - |
12+
| [cache](./cache) | Multi-backend caching with Redis and in-memory support | [Yes](./cache/config.go) | - |
13+
| [chimux](./chimux) | Chi router integration with middleware support | [Yes](./chimux/config.go) | - |
14+
| [database](./database) | Database connectivity and SQL operations with multiple driver support | [Yes](./database/config.go) | - |
15+
| [eventbus](./eventbus) | Asynchronous event handling and pub/sub messaging | [Yes](./eventbus/config.go) | - |
16+
| [httpclient](./httpclient) | Configurable HTTP client with connection pooling, timeouts, and verbose logging | [Yes](./httpclient/config.go) | - |
17+
| [httpserver](./httpserver) | HTTP/HTTPS server with TLS support, graceful shutdown, and configurable timeouts | [Yes](./httpserver/config.go) | - |
18+
| [jsonschema](./jsonschema) | JSON Schema validation services | No | - |
19+
| [letsencrypt](./letsencrypt) | SSL/TLS certificate automation with Let's Encrypt | [Yes](./letsencrypt/config.go) | Works with httpserver |
20+
| [reverseproxy](./reverseproxy) | Reverse proxy with load balancing, circuit breaker, and health monitoring | [Yes](./reverseproxy/config.go) | - |
21+
| [scheduler](./scheduler) | Job scheduling with cron expressions and worker pools | [Yes](./scheduler/config.go) | - |
3222

3323
## 🚀 Quick Start
3424

modules/letsencrypt/README.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# Let's Encrypt Module
2+
3+
The Let's Encrypt module provides automatic SSL/TLS certificate generation and management using Let's Encrypt's ACME protocol. It integrates seamlessly with the Modular framework to provide HTTPS capabilities for your applications.
4+
5+
[![Go Reference](https://pkg.go.dev/badge/github.com/GoCodeAlone/modular/modules/letsencrypt.svg)](https://pkg.go.dev/github.com/GoCodeAlone/modular/modules/letsencrypt)
6+
7+
## Features
8+
9+
- **Automatic Certificate Generation**: Obtain SSL/TLS certificates from Let's Encrypt automatically
10+
- **Multiple Challenge Types**: Support for HTTP-01 and DNS-01 challenges
11+
- **Auto-Renewal**: Automatic certificate renewal before expiration
12+
- **Multiple DNS Providers**: Support for various DNS providers (Cloudflare, Route53, Azure DNS, etc.)
13+
- **Staging Environment**: Use Let's Encrypt's staging environment for testing
14+
- **Certificate Storage**: Persistent storage of certificates and account information
15+
- **Production Ready**: Built with best practices for production deployments
16+
17+
## Installation
18+
19+
```bash
20+
go get github.com/GoCodeAlone/modular/modules/letsencrypt
21+
```
22+
23+
## Quick Start
24+
25+
### Basic Usage with HTTP Challenge
26+
27+
```go
28+
package main
29+
30+
import (
31+
"context"
32+
"log/slog"
33+
"os"
34+
35+
"github.com/GoCodeAlone/modular"
36+
"github.com/GoCodeAlone/modular/modules/letsencrypt"
37+
"github.com/GoCodeAlone/modular/modules/httpserver"
38+
)
39+
40+
type AppConfig struct {
41+
LetsEncrypt letsencrypt.LetsEncryptConfig `yaml:"letsencrypt"`
42+
HTTPServer httpserver.HTTPServerConfig `yaml:"httpserver"`
43+
}
44+
45+
func main() {
46+
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
47+
48+
config := &AppConfig{
49+
LetsEncrypt: letsencrypt.LetsEncryptConfig{
50+
Email: "your-email@example.com",
51+
Domains: []string{"example.com", "www.example.com"},
52+
UseStaging: false, // Set to true for testing
53+
StoragePath: "./certs",
54+
AutoRenew: true,
55+
RenewBefore: 30, // Renew 30 days before expiration
56+
},
57+
HTTPServer: httpserver.HTTPServerConfig{
58+
Host: "0.0.0.0",
59+
Port: 443,
60+
TLS: &httpserver.TLSConfig{Enabled: true},
61+
},
62+
}
63+
64+
configProvider := modular.NewStdConfigProvider(config)
65+
app := modular.NewStdApplication(configProvider, logger)
66+
67+
// Register modules
68+
app.RegisterModule(letsencrypt.NewLetsEncryptModule())
69+
app.RegisterModule(httpserver.NewHTTPServerModule())
70+
71+
if err := app.Run(); err != nil {
72+
logger.Error("Application error", "error", err)
73+
os.Exit(1)
74+
}
75+
}
76+
```
77+
78+
### DNS Challenge with Cloudflare
79+
80+
```go
81+
config := &AppConfig{
82+
LetsEncrypt: letsencrypt.LetsEncryptConfig{
83+
Email: "your-email@example.com",
84+
Domains: []string{"*.example.com", "example.com"},
85+
UseStaging: false,
86+
StoragePath: "./certs",
87+
AutoRenew: true,
88+
UseDNS: true,
89+
DNSProvider: &letsencrypt.DNSProviderConfig{
90+
Name: "cloudflare",
91+
},
92+
DNSConfig: map[string]string{
93+
"CLOUDFLARE_EMAIL": "your-email@example.com",
94+
"CLOUDFLARE_API_KEY": "your-api-key",
95+
},
96+
},
97+
}
98+
```
99+
100+
## Configuration
101+
102+
### LetsEncryptConfig
103+
104+
| Field | Type | Description | Default |
105+
|-------|------|-------------|---------|
106+
| `email` | `string` | Email address for Let's Encrypt registration | Required |
107+
| `domains` | `[]string` | List of domain names to obtain certificates for | Required |
108+
| `use_staging` | `bool` | Use Let's Encrypt staging environment | `false` |
109+
| `storage_path` | `string` | Directory for certificate storage | `"./letsencrypt"` |
110+
| `renew_before` | `int` | Days before expiry to renew certificates | `30` |
111+
| `auto_renew` | `bool` | Enable automatic renewal | `true` |
112+
| `use_dns` | `bool` | Use DNS-01 challenges instead of HTTP-01 | `false` |
113+
114+
### DNS Provider Configuration
115+
116+
For DNS challenges, configure the DNS provider:
117+
118+
```yaml
119+
letsencrypt:
120+
email: "your-email@example.com"
121+
domains:
122+
- "example.com"
123+
- "*.example.com"
124+
use_dns: true
125+
dns_provider:
126+
name: "cloudflare"
127+
dns_config:
128+
CLOUDFLARE_EMAIL: "your-email@example.com"
129+
CLOUDFLARE_API_KEY: "your-api-key"
130+
```
131+
132+
### Supported DNS Providers
133+
134+
- **Cloudflare**: `cloudflare`
135+
- **Route53 (AWS)**: `route53`
136+
- **Azure DNS**: `azuredns`
137+
- **Google Cloud DNS**: `gcloud`
138+
- **DigitalOcean**: `digitalocean`
139+
- **Namecheap**: `namecheap`
140+
141+
Each provider requires specific environment variables or configuration parameters.
142+
143+
## Integration with HTTP Server
144+
145+
The Let's Encrypt module works seamlessly with the HTTP Server module by implementing the `CertificateService` interface:
146+
147+
```go
148+
// The HTTP server module will automatically use certificates from Let's Encrypt
149+
app.RegisterModule(letsencrypt.NewLetsEncryptModule())
150+
app.RegisterModule(httpserver.NewHTTPServerModule())
151+
```
152+
153+
## Advanced Usage
154+
155+
### Custom Certificate Handling
156+
157+
```go
158+
// Get certificate service for custom handling
159+
var certService httpserver.CertificateService
160+
app.GetService("certificateService", &certService)
161+
162+
// Get certificate for a specific domain
163+
cert := certService.GetCertificate("example.com")
164+
```
165+
166+
### Manual Certificate Operations
167+
168+
```go
169+
letsEncryptModule := letsencrypt.NewLetsEncryptModule()
170+
171+
// Force certificate renewal
172+
if err := letsEncryptModule.RenewCertificate("example.com"); err != nil {
173+
log.Printf("Failed to renew certificate: %v", err)
174+
}
175+
```
176+
177+
## Environment Variables
178+
179+
You can configure the module using environment variables:
180+
181+
```bash
182+
LETSENCRYPT_EMAIL=your-email@example.com
183+
LETSENCRYPT_DOMAINS=example.com,www.example.com
184+
LETSENCRYPT_USE_STAGING=false
185+
LETSENCRYPT_STORAGE_PATH=./certs
186+
LETSENCRYPT_AUTO_RENEW=true
187+
```
188+
189+
## Best Practices
190+
191+
1. **Use Staging for Testing**: Always test with `use_staging: true` to avoid rate limits
192+
2. **Secure Storage**: Ensure certificate storage directory has proper permissions
193+
3. **Monitor Renewals**: Set up monitoring for certificate renewal failures
194+
4. **Backup Certificates**: Regularly backup your certificate storage directory
195+
5. **DNS Challenge for Wildcards**: Use DNS challenges for wildcard certificates
196+
197+
## Troubleshooting
198+
199+
### Common Issues
200+
201+
1. **Rate Limits**: Use staging environment for testing
202+
2. **DNS Propagation**: DNS challenges may take time to propagate
203+
3. **Firewall**: Ensure port 80 is accessible for HTTP challenges
204+
4. **Domain Validation**: Verify domain ownership and DNS configuration
205+
206+
### Debug Mode
207+
208+
Enable debug logging to troubleshoot issues:
209+
210+
```go
211+
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
212+
Level: slog.LevelDebug,
213+
}))
214+
```
215+
216+
## Examples
217+
218+
See the [examples directory](../../examples/) for complete working examples:
219+
220+
- Basic HTTPS server with Let's Encrypt
221+
- Multi-domain certificate management
222+
- DNS challenge configuration
223+
224+
## Dependencies
225+
226+
- [lego](https://github.com/go-acme/lego) - ACME client library
227+
- Works with the [httpserver](../httpserver/) module for HTTPS support
228+
229+
## License
230+
231+
This module is part of the Modular framework and is licensed under the [MIT License](../../LICENSE).

0 commit comments

Comments
 (0)