mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-01-16 09:42:09 +01:00
refactor(core)!: Add context, config, and structured logging
Introduces `context.Context` to the `FetchCourse` method and its call chain, allowing for cancellable network requests and timeouts. This improves application robustness when fetching remote course data. A new configuration package centralizes application settings, loading them from environment variables with sensible defaults for base URL, request timeout, and logging. Standard `log` and `fmt` calls are replaced with a structured logging system built on `slog`, supporting both JSON and human-readable text formats. This change also includes: - Extensive benchmarks and example tests. - Simplified Go doc comments across several packages. BREAKING CHANGE: The `NewArticulateParser` constructor signature has been updated to accept a logger, base URL, and timeout, which are now supplied via the new configuration system.
This commit is contained in:
27
internal/interfaces/logger.go
Normal file
27
internal/interfaces/logger.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Package interfaces provides the core contracts for the articulate-parser application.
|
||||
// It defines interfaces for parsing and exporting Articulate Rise courses.
|
||||
package interfaces
|
||||
|
||||
import "context"
|
||||
|
||||
// Logger defines the interface for structured logging.
|
||||
// Implementations should provide leveled, structured logging capabilities.
|
||||
type Logger interface {
|
||||
// Debug logs a debug-level message with optional key-value pairs.
|
||||
Debug(msg string, keysAndValues ...any)
|
||||
|
||||
// Info logs an info-level message with optional key-value pairs.
|
||||
Info(msg string, keysAndValues ...any)
|
||||
|
||||
// Warn logs a warning-level message with optional key-value pairs.
|
||||
Warn(msg string, keysAndValues ...any)
|
||||
|
||||
// Error logs an error-level message with optional key-value pairs.
|
||||
Error(msg string, keysAndValues ...any)
|
||||
|
||||
// With returns a new logger with the given key-value pairs added as context.
|
||||
With(keysAndValues ...any) Logger
|
||||
|
||||
// WithContext returns a new logger with context information.
|
||||
WithContext(ctx context.Context) Logger
|
||||
}
|
||||
Reference in New Issue
Block a user