formatter

package
v0.0.0-...-812ebae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchFormatter

type BatchFormatter struct {
	// contains filtered or unexported fields
}

BatchFormatter handles formatting of large datasets with performance optimizations

func NewBatchFormatter

func NewBatchFormatter(formatter Formatter, config *Config) *BatchFormatter

NewBatchFormatter creates a new batch formatter

func (*BatchFormatter) FormatArticlesBatch

func (bf *BatchFormatter) FormatArticlesBatch(articles []models.Article) (string, error)

FormatArticlesBatch formats articles in batches for better performance

func (*BatchFormatter) FormatRepositoriesBatch

func (bf *BatchFormatter) FormatRepositoriesBatch(repositories []models.Repository) (string, error)

FormatRepositoriesBatch formats repositories in batches for better performance

type Config

type Config struct {
	// Format specifies the output format (json, markdown, text)
	Format OutputFormat `json:"format"`

	// Indent specifies indentation for structured formats (JSON)
	Indent string `json:"indent"`

	// DateFormat specifies the date format string
	DateFormat string `json:"dateFormat"`

	// IncludeMetadata determines whether to include metadata in output
	IncludeMetadata bool `json:"includeMetadata"`

	// IncludeContent determines whether to include full content (can be large)
	IncludeContent bool `json:"includeContent"`

	// MaxSummaryLength limits the length of summaries in output
	MaxSummaryLength int `json:"maxSummaryLength"`

	// SortBy specifies how to sort results (relevance, quality, date, title)
	SortBy string `json:"sortBy"`

	// SortOrder specifies sort direction (asc, desc)
	SortOrder string `json:"sortOrder"`

	// EnableLinks determines whether to make URLs clickable in supported formats
	EnableLinks bool `json:"enableLinks"`

	// CompactOutput reduces whitespace for smaller output
	CompactOutput bool `json:"compactOutput"`
}

Config represents configuration options for formatting

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration

type Formatter

type Formatter interface {
	// FormatArticles formats a slice of articles according to the configuration
	FormatArticles(articles []models.Article) (string, error)

	// FormatRepositories formats a slice of repositories according to the configuration
	FormatRepositories(repositories []models.Repository) (string, error)

	// FormatMixed formats both articles and repositories in a unified output
	FormatMixed(articles []models.Article, repositories []models.Repository) (string, error)

	// GetSupportedFormats returns the formats supported by this formatter
	GetSupportedFormats() []OutputFormat
}

Formatter defines the interface for all formatters

type FormatterFactory

type FormatterFactory struct {
	// contains filtered or unexported fields
}

FormatterFactory creates formatters based on configuration

func NewFormatterFactory

func NewFormatterFactory(config *Config) *FormatterFactory

NewFormatterFactory creates a new formatter factory with the given configuration

func (*FormatterFactory) CreateFormatter

func (ff *FormatterFactory) CreateFormatter() (Formatter, error)

CreateFormatter creates a formatter based on the configured format

func (*FormatterFactory) GetConfig

func (ff *FormatterFactory) GetConfig() Config

GetConfig returns a copy of the current configuration

func (*FormatterFactory) SetFormat

func (ff *FormatterFactory) SetFormat(format OutputFormat)

SetFormat updates the output format in the configuration

func (*FormatterFactory) UpdateConfig

func (ff *FormatterFactory) UpdateConfig(config *Config)

UpdateConfig updates the factory configuration

type JSONFormatter

type JSONFormatter struct {
	// contains filtered or unexported fields
}

JSONFormatter implements the JSON output format with proper structure and indentation

func NewJSONFormatter

func NewJSONFormatter(config *Config) *JSONFormatter

NewJSONFormatter creates a new JSON formatter with the given configuration

func (*JSONFormatter) FormatArticles

func (jf *JSONFormatter) FormatArticles(articles []models.Article) (string, error)

FormatArticles formats a slice of articles as JSON

func (*JSONFormatter) FormatMixed

func (jf *JSONFormatter) FormatMixed(articles []models.Article, repositories []models.Repository) (string, error)

FormatMixed formats both articles and repositories in a unified JSON output

func (*JSONFormatter) FormatRepositories

func (jf *JSONFormatter) FormatRepositories(repositories []models.Repository) (string, error)

FormatRepositories formats a slice of repositories as JSON

func (*JSONFormatter) GetSupportedFormats

func (jf *JSONFormatter) GetSupportedFormats() []OutputFormat

GetSupportedFormats returns the formats supported by this formatter

type MarkdownFormatter

type MarkdownFormatter struct {
	// contains filtered or unexported fields
}

MarkdownFormatter implements the Markdown output format with readable layout and links

func NewMarkdownFormatter

func NewMarkdownFormatter(config *Config) *MarkdownFormatter

NewMarkdownFormatter creates a new Markdown formatter with the given configuration

func (*MarkdownFormatter) FormatArticles

func (mf *MarkdownFormatter) FormatArticles(articles []models.Article) (string, error)

FormatArticles formats a slice of articles as Markdown

func (*MarkdownFormatter) FormatMixed

func (mf *MarkdownFormatter) FormatMixed(articles []models.Article, repositories []models.Repository) (string, error)

FormatMixed formats both articles and repositories in a unified Markdown output

func (*MarkdownFormatter) FormatRepositories

func (mf *MarkdownFormatter) FormatRepositories(repositories []models.Repository) (string, error)

FormatRepositories formats a slice of repositories as Markdown

func (*MarkdownFormatter) GetSupportedFormats

func (mf *MarkdownFormatter) GetSupportedFormats() []OutputFormat

GetSupportedFormats returns the formats supported by this formatter

type OutputFormat

type OutputFormat string

OutputFormat represents the supported output formats

const (
	FormatJSON     OutputFormat = "json"
	FormatMarkdown OutputFormat = "markdown"
	FormatText     OutputFormat = "text"
)

type TextFormatter

type TextFormatter struct {
	// contains filtered or unexported fields
}

TextFormatter implements the plain text output format for simple, readable output

func NewTextFormatter

func NewTextFormatter(config *Config) *TextFormatter

NewTextFormatter creates a new text formatter with the given configuration

func (*TextFormatter) FormatArticles

func (tf *TextFormatter) FormatArticles(articles []models.Article) (string, error)

FormatArticles formats a slice of articles as plain text

func (*TextFormatter) FormatMixed

func (tf *TextFormatter) FormatMixed(articles []models.Article, repositories []models.Repository) (string, error)

FormatMixed formats both articles and repositories in a unified text output

func (*TextFormatter) FormatRepositories

func (tf *TextFormatter) FormatRepositories(repositories []models.Repository) (string, error)

FormatRepositories formats a slice of repositories as plain text

func (*TextFormatter) GetSupportedFormats

func (tf *TextFormatter) GetSupportedFormats() []OutputFormat

GetSupportedFormats returns the formats supported by this formatter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL