Documentation
¶
Overview ¶
Package services provides the core functionality for the articulate-parser application. It implements the interfaces defined in the interfaces package.
Index ¶
- func NewArticulateParser(logger interfaces.Logger, baseURL string, timeout time.Duration) interfaces.CourseParser
- func NewNoOpLogger() interfaces.Logger
- func NewSlogLogger(level slog.Level) interfaces.Logger
- func NewTextLogger(level slog.Level) interfaces.Logger
- type App
- type ArticulateParser
- type HTMLCleaner
- type NoOpLogger
- func (l *NoOpLogger) Debug(msg string, keysAndValues ...any)
- func (l *NoOpLogger) Error(msg string, keysAndValues ...any)
- func (l *NoOpLogger) Info(msg string, keysAndValues ...any)
- func (l *NoOpLogger) Warn(msg string, keysAndValues ...any)
- func (l *NoOpLogger) With(keysAndValues ...any) interfaces.Logger
- func (l *NoOpLogger) WithContext(ctx context.Context) interfaces.Logger
- type SlogLogger
- func (l *SlogLogger) Debug(msg string, keysAndValues ...any)
- func (l *SlogLogger) Error(msg string, keysAndValues ...any)
- func (l *SlogLogger) Info(msg string, keysAndValues ...any)
- func (l *SlogLogger) Warn(msg string, keysAndValues ...any)
- func (l *SlogLogger) With(keysAndValues ...any) interfaces.Logger
- func (l *SlogLogger) WithContext(ctx context.Context) interfaces.Logger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewArticulateParser ¶
func NewArticulateParser(logger interfaces.Logger, baseURL string, timeout time.Duration) interfaces.CourseParser
NewArticulateParser creates a new ArticulateParser instance. If baseURL is empty, uses the default Articulate Rise API URL. If timeout is zero, uses a 30-second timeout.
Example ¶
ExampleNewArticulateParser demonstrates creating a new parser.
package main
import (
"fmt"
"github.com/kjanat/articulate-parser/internal/services"
)
func main() {
// Create a no-op logger for this example
logger := services.NewNoOpLogger()
// Create parser with defaults
parser := services.NewArticulateParser(logger, "", 0)
fmt.Printf("Parser created: %T\n", parser)
}
Output: Parser created: *services.ArticulateParser
Example (Custom) ¶
ExampleNewArticulateParser_custom demonstrates creating a parser with custom configuration.
package main
import (
"fmt"
"github.com/kjanat/articulate-parser/internal/services"
)
func main() {
logger := services.NewNoOpLogger()
// Create parser with custom base URL and timeout
parser := services.NewArticulateParser(
logger,
"https://custom.articulate.com",
60_000_000_000, // 60 seconds in nanoseconds
)
fmt.Printf("Parser configured: %T\n", parser)
}
Output: Parser configured: *services.ArticulateParser
func NewNoOpLogger ¶ added in v1.0.0
func NewNoOpLogger() interfaces.Logger
NewNoOpLogger creates a logger that discards all messages.
func NewSlogLogger ¶ added in v1.0.0
func NewSlogLogger(level slog.Level) interfaces.Logger
NewSlogLogger creates a new structured logger using slog. The level parameter controls the minimum log level (debug, info, warn, error).
func NewTextLogger ¶ added in v1.0.0
func NewTextLogger(level slog.Level) interfaces.Logger
NewTextLogger creates a new structured logger with human-readable text output. Useful for development and debugging.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App represents the main application service that coordinates the parsing and exporting of Articulate Rise courses. It serves as the primary entry point for the application's functionality.
func NewApp ¶
func NewApp(parser interfaces.CourseParser, exporterFactory interfaces.ExporterFactory) *App
NewApp creates a new application instance with dependency injection. It takes a CourseParser for loading courses and an ExporterFactory for creating the appropriate exporters.
func (*App) ProcessCourseFromFile ¶
ProcessCourseFromFile loads a course from a local file and exports it to the specified format. It takes the path to the course file, the desired export format, and the output file path. Returns an error if loading or exporting fails.
func (*App) ProcessCourseFromURI ¶
ProcessCourseFromURI fetches a course from the provided URI and exports it to the specified format. It takes the URI to fetch the course from, the desired export format, and the output file path. Returns an error if fetching or exporting fails.
func (*App) SupportedFormats ¶ added in v1.0.0
SupportedFormats returns a list of all export formats supported by the application. This information is provided by the ExporterFactory.
type ArticulateParser ¶
type ArticulateParser struct {
// BaseURL is the root URL for the Articulate Rise API
BaseURL string
// Client is the HTTP client used to make requests to the API
Client *http.Client
// Logger for structured logging
Logger interfaces.Logger
}
ArticulateParser implements the CourseParser interface specifically for Articulate Rise courses. It can fetch courses from the Articulate Rise API or load them from local JSON files.
func (*ArticulateParser) FetchCourse ¶
FetchCourse fetches a course from the given URI and returns the parsed course data. The URI should be an Articulate Rise share URL (e.g., https://rise.articulate.com/share/SHARE_ID). The context can be used for cancellation and timeout control.
Example ¶
ExampleArticulateParser_FetchCourse demonstrates fetching a course from a URI.
package main
import (
"context"
"log"
"github.com/kjanat/articulate-parser/internal/services"
)
func main() {
logger := services.NewNoOpLogger()
parser := services.NewArticulateParser(logger, "", 0)
// Create a context with timeout
ctx := context.Background()
// In a real scenario, you'd use an actual share URL
_, err := parser.FetchCourse(ctx, "https://rise.articulate.com/share/YOUR_SHARE_ID")
if err != nil {
log.Printf("Failed to fetch course: %v", err)
}
}
Output:
func (*ArticulateParser) LoadCourseFromFile ¶
func (p *ArticulateParser) LoadCourseFromFile(filePath string) (*models.Course, error)
LoadCourseFromFile loads an Articulate Rise course from a local JSON file.
Example ¶
ExampleArticulateParser_LoadCourseFromFile demonstrates loading a course from a file.
package main
import (
"log"
"github.com/kjanat/articulate-parser/internal/services"
)
func main() {
logger := services.NewNoOpLogger()
parser := services.NewArticulateParser(logger, "", 0)
// In a real scenario, you'd have an actual file
// This example shows the API usage
_, err := parser.LoadCourseFromFile("course.json")
if err != nil {
log.Printf("Failed to load course: %v", err)
}
}
Output:
type HTMLCleaner ¶
type HTMLCleaner struct{}
HTMLCleaner provides utilities for converting HTML content to plain text. It removes HTML tags while preserving their content and converts HTML entities to their plain text equivalents using proper HTML parsing instead of regex.
Example ¶
ExampleHTMLCleaner demonstrates cleaning HTML content.
package main
import (
"fmt"
"github.com/kjanat/articulate-parser/internal/services"
)
func main() {
cleaner := services.NewHTMLCleaner()
html := "<p>This is <strong>bold</strong> text with entities.</p>"
clean := cleaner.CleanHTML(html)
fmt.Println(clean)
}
Output: This is bold text with entities.
func NewHTMLCleaner ¶
func NewHTMLCleaner() *HTMLCleaner
NewHTMLCleaner creates a new HTML cleaner instance. This service is typically injected into exporters that need to handle HTML content from Articulate Rise courses.
func (*HTMLCleaner) CleanHTML ¶
func (h *HTMLCleaner) CleanHTML(htmlStr string) string
CleanHTML removes HTML tags and converts entities, returning clean plain text. It parses the HTML into a node tree and extracts only text content, skipping script and style tags. HTML entities are automatically handled by the parser, and whitespace is normalized.
Example ¶
ExampleHTMLCleaner_CleanHTML demonstrates complex HTML cleaning.
package main
import (
"fmt"
"github.com/kjanat/articulate-parser/internal/services"
)
func main() {
cleaner := services.NewHTMLCleaner()
html := `
<div>
<h1>Title</h1>
<p>Paragraph with <a href="#">link</a> and & entity.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
`
clean := cleaner.CleanHTML(html)
fmt.Println(clean)
}
Output: Title Paragraph with link and & entity. Item 1 Item 2
type NoOpLogger ¶ added in v1.0.0
type NoOpLogger struct{}
NoOpLogger is a logger that discards all log messages. Useful for testing or when logging should be disabled.
func (*NoOpLogger) Debug ¶ added in v1.0.0
func (l *NoOpLogger) Debug(msg string, keysAndValues ...any)
Debug does nothing.
func (*NoOpLogger) Error ¶ added in v1.0.0
func (l *NoOpLogger) Error(msg string, keysAndValues ...any)
Error does nothing.
func (*NoOpLogger) Info ¶ added in v1.0.0
func (l *NoOpLogger) Info(msg string, keysAndValues ...any)
Info does nothing.
func (*NoOpLogger) Warn ¶ added in v1.0.0
func (l *NoOpLogger) Warn(msg string, keysAndValues ...any)
Warn does nothing.
func (*NoOpLogger) With ¶ added in v1.0.0
func (l *NoOpLogger) With(keysAndValues ...any) interfaces.Logger
With returns the same no-op logger.
func (*NoOpLogger) WithContext ¶ added in v1.0.0
func (l *NoOpLogger) WithContext(ctx context.Context) interfaces.Logger
WithContext returns the same no-op logger.
type SlogLogger ¶ added in v1.0.0
type SlogLogger struct {
// contains filtered or unexported fields
}
SlogLogger implements the Logger interface using the standard library's slog package.
func (*SlogLogger) Debug ¶ added in v1.0.0
func (l *SlogLogger) Debug(msg string, keysAndValues ...any)
Debug logs a debug-level message with optional key-value pairs.
func (*SlogLogger) Error ¶ added in v1.0.0
func (l *SlogLogger) Error(msg string, keysAndValues ...any)
Error logs an error-level message with optional key-value pairs.
func (*SlogLogger) Info ¶ added in v1.0.0
func (l *SlogLogger) Info(msg string, keysAndValues ...any)
Info logs an info-level message with optional key-value pairs.
func (*SlogLogger) Warn ¶ added in v1.0.0
func (l *SlogLogger) Warn(msg string, keysAndValues ...any)
Warn logs a warning-level message with optional key-value pairs.
func (*SlogLogger) With ¶ added in v1.0.0
func (l *SlogLogger) With(keysAndValues ...any) interfaces.Logger
With returns a new logger with the given key-value pairs added as context.
func (*SlogLogger) WithContext ¶ added in v1.0.0
func (l *SlogLogger) WithContext(ctx context.Context) interfaces.Logger
WithContext returns a new logger with context information. Currently preserves the logger as-is, but can be extended to extract trace IDs or other context values in the future.