Documentation
¶
Index ¶
- Constants
- func ParseAt(value string, location *time.Location) (time.Time, error)
- func ParseWindowAt(value string, location *time.Location) (time.Time, error)
- func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) error
- func ValidateArticleURL(rawURL string) error
- type BoolValue
- type CLIValues
- type CollectedURL
- type CommandRunner
- type Config
- type DailyTime
- type DailyWindow
- func (d *DailyWindow) Containing(instant time.Time) (Window, error)
- func (d *DailyWindow) LastComplete(reference time.Time) (Window, error)
- func (d *DailyWindow) Select(reference time.Time, at *time.Time) (Window, error)
- func (d *DailyWindow) SelectMany(reference time.Time, at *time.Time, count int) ([]Window, error)
- type ExecCommandRunner
- type FeedFetcher
- type FeedItem
- type IntValue
- type LookupEnvFunc
- type MDHQ
- type MDHQGetter
- type MDHQOptions
- type MDHQResult
- type Pipeline
- type PipelineRequest
- type RSSnipFetcher
- type ResolvedConfig
- type Source
- type StringValue
- type Window
- type WindowConfig
Constants ¶
const DefaultConfigPath = "metabol.yaml"
const MaxWindowCount = 366
MaxWindowCount limits one run to at most one leap year's worth of daily windows.
Variables ¶
This section is empty.
Functions ¶
func ParseWindowAt ¶
ParseWindowAt parses an RFC3339 instant or a YYYY-MM-DD date. Date-only values denote local midnight in location and use the same DST resolution rules as daily boundaries.
func ValidateArticleURL ¶
ValidateArticleURL checks that rawURL is an absolute HTTP(S) URL without userinfo. Feed items are untrusted input that metabol passes to mdhq as a command-line argument, so values such as "--root=/tmp" or "mailto:x" must never reach the downstream command.
Types ¶
type BoolValue ¶
type BoolValue struct {
// contains filtered or unexported fields
}
BoolValue is a boolean flag value that distinguishes unset from false.
func (*BoolValue) IsBoolFlag ¶
IsBoolFlag allows boolean options to mean true without an argument.
type CLIValues ¶
type CLIValues struct {
Config StringValue
Root StringValue
Assets BoolValue
Update BoolValue
Catchup BoolValue
Timezone StringValue
At StringValue
WindowCount IntValue
}
CLIValues contains configuration-related command-line values.
func (CLIValues) ConfigPath ¶
func (v CLIValues) ConfigPath(lookupEnv LookupEnvFunc) (path string, explicit bool, err error)
ConfigPath resolves CLI > METABOL_CONFIG > the default configuration path. Explicit reports whether CLI or the environment selected the path.
func (*CLIValues) RegisterFlags ¶
RegisterFlags registers configuration-related flags on fs.
type CollectedURL ¶
CollectedURL retains the feed that produced an article URL.
func CollectFeeds ¶
func CollectFeeds( ctx context.Context, fetcher FeedFetcher, sources []string, since time.Time, until *time.Time, ) ([]CollectedURL, error)
CollectFeeds collects unique article URLs in source and feed item order.
Collection continues after source failures. The returned error joins every source failure and every rejected article URL, while the returned URLs contain all successfully collected items. Article URLs that are not absolute HTTP(S) URLs are rejected rather than forwarded to mdhq, because feed items are untrusted input that becomes a command-line argument.
type CommandRunner ¶
type CommandRunner interface {
Run(ctx context.Context, name string, args ...string) (stdout, stderr []byte, err error)
}
CommandRunner runs an external command and keeps its stdout and stderr separate.
type Config ¶
type Config struct {
Root string `yaml:"root"`
Assets *bool `yaml:"assets"`
Update *bool `yaml:"update"`
Catchup *bool `yaml:"catchup"`
Timezone string `yaml:"timezone"`
Window WindowConfig `yaml:"window"`
Sources []Source `yaml:"sources"`
}
Config is the YAML configuration for metabol.
func LoadConfig ¶
LoadConfig reads and validates exactly path; it does not search fallback paths.
type DailyTime ¶
DailyTime is a parsed local-time daily boundary.
func ParseDailyTime ¶
ParseDailyTime parses an exact 24-hour HH:MM value.
type DailyWindow ¶
type DailyWindow struct {
// contains filtered or unexported fields
}
DailyWindow selects windows separated by a fixed local wall-clock time.
func NewDailyWindow ¶
func NewDailyWindow(location *time.Location, boundary string) (*DailyWindow, error)
NewDailyWindow creates a daily window selector in location.
func NewDailyWindowForTimezone ¶
func NewDailyWindowForTimezone(timezone, boundary string) (*DailyWindow, error)
NewDailyWindowForTimezone loads timezone and creates a daily window selector.
func NewDailyWindowFromTime ¶
func NewDailyWindowFromTime(location *time.Location, boundary DailyTime) (*DailyWindow, error)
NewDailyWindowFromTime creates a selector from an already parsed boundary.
func (*DailyWindow) Containing ¶
func (d *DailyWindow) Containing(instant time.Time) (Window, error)
Containing returns the half-open window containing instant.
func (*DailyWindow) LastComplete ¶
func (d *DailyWindow) LastComplete(reference time.Time) (Window, error)
LastComplete returns the last window whose end is not after reference.
func (*DailyWindow) Select ¶
Select returns the window containing at when at is non-nil. Otherwise it returns the last window whose end is not after reference.
func (*DailyWindow) SelectMany ¶
SelectMany returns count consecutive windows ending with the selected window, ordered from oldest to newest.
type ExecCommandRunner ¶
type ExecCommandRunner struct{}
ExecCommandRunner runs commands with os/exec.
type FeedFetcher ¶
type FeedFetcher interface {
Fetch(ctx context.Context, sourceURL string, since time.Time, until *time.Time) ([]FeedItem, error)
}
FeedFetcher fetches feed items since a lower bound and, when non-nil, before an upper bound.
type FeedItem ¶
type FeedItem struct {
URL string
}
FeedItem is the part of an rssnip item needed by the pipeline.
type IntValue ¶
type IntValue struct {
// contains filtered or unexported fields
}
IntValue is an integer flag value that distinguishes unset from zero.
type LookupEnvFunc ¶
LookupEnvFunc matches os.LookupEnv and is injectable for deterministic tests.
type MDHQ ¶
type MDHQ struct {
Runner CommandRunner
Command string
}
MDHQ invokes the mdhq command once per URL.
func NewMDHQ ¶
func NewMDHQ(runner CommandRunner) *MDHQ
NewMDHQ constructs an mdhq client. A nil runner uses os/exec.
func (*MDHQ) Get ¶
func (m *MDHQ) Get( ctx context.Context, url string, options MDHQOptions, ) (MDHQResult, error)
Get fetches one URL and returns its attributed mdhq result.
type MDHQGetter ¶
type MDHQGetter interface {
Get(ctx context.Context, url string, options MDHQOptions) (MDHQResult, error)
}
MDHQGetter saves one URL with mdhq.
type MDHQOptions ¶
MDHQOptions controls mdhq storage behavior.
type MDHQResult ¶
type MDHQResult struct {
RequestedURL string `json:"requestedUrl"`
SourceURL string `json:"sourceUrl"`
Path string `json:"path"`
Status string `json:"status"`
Diagnostic string `json:"-"`
}
MDHQResult is the stable subset of mdhq's JSON result emitted by metabol.
type Pipeline ¶
type Pipeline struct {
Fetcher FeedFetcher
MDHQ MDHQGetter
}
Pipeline coordinates feed collection and mdhq.
func NewPipeline ¶
func NewPipeline(fetcher FeedFetcher, mdhq MDHQGetter) *Pipeline
NewPipeline constructs a pipeline with injectable dependencies.
type PipelineRequest ¶
type PipelineRequest struct {
Sources []string
Since time.Time
Until *time.Time
Root string
Assets bool
Update bool
}
PipelineRequest describes one feed collection and mdhq run. A nil Until leaves the feed collection upper bound open.
type RSSnipFetcher ¶
type RSSnipFetcher struct{}
RSSnipFetcher fetches feeds with the rssnip library.
type ResolvedConfig ¶
type ResolvedConfig struct {
ConfigPath string
Root string
Assets bool
Update bool
Catchup bool
Location *time.Location
Daily DailyTime
WindowCount int
At *time.Time
Sources []Source
}
ResolvedConfig contains values after applying CLI, environment, YAML, and downstream/default fallbacks.
func LoadResolvedConfig ¶
func LoadResolvedConfig(cli CLIValues, lookupEnv LookupEnvFunc) (*ResolvedConfig, error)
LoadResolvedConfig selects, loads, and resolves the configuration.
func ResolveConfig ¶
func ResolveConfig(cli CLIValues, config *Config, lookupEnv LookupEnvFunc) (*ResolvedConfig, error)
ResolveConfig applies CLI > METABOL_* > YAML values. Callers must provide root through one of these sources because this entry point has no path fallback. Assets and update default to false, and timezone defaults to the local timezone.
type Source ¶
Source describes an input feed.
func (*Source) UnmarshalYAML ¶
UnmarshalYAML accepts either a URL scalar or a source mapping.
type StringValue ¶
type StringValue struct {
// contains filtered or unexported fields
}
StringValue is a flag value that distinguishes an unset value from an explicitly supplied empty string.
func (StringValue) Get ¶
func (v StringValue) Get() (string, bool)
Get returns the value and whether it was explicitly set.
func (*StringValue) Set ¶
func (v *StringValue) Set(value string) error
func (*StringValue) String ¶
func (v *StringValue) String() string
type Window ¶
Window is a half-open interval [Start, End).
func SelectDailyWindow ¶
func SelectDailyWindow( location *time.Location, boundary DailyTime, reference time.Time, at *time.Time, ) (Window, error)
SelectDailyWindow creates a selector from resolved configuration and selects either the last complete window or, when at is non-nil, its containing window.
type WindowConfig ¶
WindowConfig describes logical window selection.