gofeed icon indicating copy to clipboard operation
gofeed copied to clipboard

v2: Refactor translator interfaces for type safety

Open mmcdole opened this issue 7 months ago • 0 comments

Overview

Refactor translator interfaces to use format-specific types instead of generic interface{}, providing better compile-time guarantees and clearer contracts.

Current State

type Translator interface {
    Translate(feed interface{}, opts *ParseOptions) (*Feed, error)
}

Proposed Design

type AtomTranslator interface {
    Translate(feed *atom.Feed, opts *ParseOptions) (*gofeed.Feed, error)
}

type RSSTranslator interface {
    Translate(feed *rss.Feed, opts *ParseOptions) (*gofeed.Feed, error)
}

type JSONTranslator interface {
    Translate(feed *json.Feed, opts *ParseOptions) (*gofeed.Feed, error)
}

Tasks

  • [ ] Define format-specific translator interfaces
  • [ ] Update Parser to use specific translator types
  • [ ] Update default translators to implement new interfaces
  • [ ] Remove generic Translator interface
  • [ ] Update documentation for custom translators

Benefits

  • Compile-time type safety - no more interface{} and type assertions
  • Clearer API contracts for custom translator implementations
  • Better IDE support with proper types
  • Eliminates runtime type errors in translators

Migration

Users with custom translators will need to update their implementations to use the specific interfaces rather than the generic one.

Related Issues

  • Part of v2 RFC (#241)

mmcdole avatar May 26 '25 04:05 mmcdole