feed

package
v0.0.0-...-d2d5c45 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventID

func NewEventID(URL string) uuid.UUID

func ValidateSchema

func ValidateSchema(db *sql.DB) error

Migrate migrates the Postgres schema to the current version.

Types

type DBConfig

type DBConfig struct {
	DBConnMaxLifetime string `usage:"max lifetime for a db connection, duration format e.g. '10s', '1m'" value:"300s"`
	DBMaxIdleConns    int    `usage:"max idle database connections" value:"10"`
	DBMaxOpenConns    int    `usage:"max open database connections" value:"10"`
	PGDatabase        string `name:"pgdb" env:"PGDATABASE"`
	PGHost            string `name:"pghost" env:"PGHOST"`
	PGPassword        string `name:"pgpassword" env:"PGPASSWORD"`
	PGPort            int    `name:"pgport" env:"PGPORT" value:"5432"`
	PGSSLMode         string `name:"pgsslmode" env:"PGSSLMODE"`
	PGUser            string `name:"pguser" env:"PGUSER"`
}

DBConfig contains database-releated config settings Note: naming in this config shares namespace with the global config, hence the "DB" and "PG" prefixes for its keys.

func (*DBConfig) OpenDB

func (c *DBConfig) OpenDB() (*sql.DB, error)

OpenDB opens a new sql.DB using pgx's stdlib bindings

func (*DBConfig) URL

func (c *DBConfig) URL() *url.URL

URL fetches the pgconfig as a connection string url

type Event

type Event struct {
	ID              uuid.UUID
	URL             string
	Title           string
	Region          string
	Description     string
	ArticleContents string
	Revision        int32
	CreateTime      time.Time
	PublishTime     time.Time
	ContentHash     []byte
}

func EventsFromRSS

func EventsFromRSS(ctx context.Context, regionIDs []string) ([]Event, error)

type EventCreator

type EventCreator interface {
	// CreateEvents creates the provided events.
	CreateEvents(context.Context, []Event) error
}

EventCreator creates events.

type EventLister

type EventLister interface {
	// ListUniqueEvents lists events. If ids is non-empty, it is used to filter the
	// result.
	ListUniqueEvents(ctx context.Context, ids []uuid.UUID) ([]Event, error)
}

EventLister lists events using an optional filter.

type EventListerCreator

type EventListerCreator interface {
	EventCreator
	EventLister
}

EventListerCreator supprots both creating and listing events. This is required by the target of the Update functionality.

type EventStorage

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

func NewEventStorage

func NewEventStorage(db *sql.DB) *EventStorage

func (*EventStorage) CreateEvents

func (s *EventStorage) CreateEvents(
	ctx context.Context, events []Event,
) (retErr error)

func (*EventStorage) ListUniqueEvents

func (s *EventStorage) ListUniqueEvents(
	ctx context.Context,
	ids []uuid.UUID,
) ([]Event, error)

type RSS

type RSS struct {
	XMLName xml.Name `xml:"rss"`
	Channel RSSChannel
}

type RSSAdapter

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

RSSAdapter makes it possible to use the RSS Events functions as an EventLister.

func NewRSSAdapter

func NewRSSAdapter(
	regionIDs []string,
	readFn func(ctx context.Context, regionIDs []string) ([]Event, error),
) *RSSAdapter

func (*RSSAdapter) ListUniqueEvents

func (a *RSSAdapter) ListUniqueEvents(ctx context.Context, ids []uuid.UUID) ([]Event, error)

ListUniqueEvents lists events found in the RSS feeds for the given regions

type RSSChannel

type RSSChannel struct {
	XMLName     xml.Name      `xml:"channel"`
	Title       string        `xml:"title"`
	Link        string        `xml:"link"`
	Description string        `xml:"description"`
	Items       []RSSFeedItem `xml:"item"`
}

type RSSFeedItem

type RSSFeedItem struct {
	XMLName     xml.Name `xml:"item"`
	Guid        string   `xml:"guid"`
	Title       string   `xml:"title"`
	Description string   `xml:"description"`
	PubDateStr  string   `xml:"pubDate"`
	Link        string   `xml:"link"`
}

type Updater

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

func NewUpdater

func NewUpdater() *Updater

func (*Updater) Update

func (u *Updater) Update(
	ctx context.Context,
	rss EventLister,
	target EventListerCreator,
) error

Update updates the provided database with records from the Police RSS feed on an interval given by refreshTime.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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