internal/importer/importer.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | package importer
import (
"context"
"alin.ovh/searchix/internal/config"
"alin.ovh/searchix/internal/nix"
"alin.ovh/searchix/internal/storage"
)
type Processor interface {
Process(context.Context) (<-chan nix.Importable, <-chan error)
}
type (
ImportSource func(context.Context) (<-chan nix.Importable, <-chan error)
ImportDestination func(context.Context, <-chan nix.Importable) <-chan error
)
func (imp *Importer) indexSource(
ctx context.Context,
source *config.Source,
) (bool, error) {
var exporter func(context.Context) (<-chan nix.Importable, <-chan error)
switch source.Importer {
case config.Packages:
exporter = storage.MakeSourceExporter[nix.Package](imp.options.Storage, source)
case config.Options:
exporter = storage.MakeSourceExporter[nix.Option](imp.options.Storage, source)
}
return pipe(
ctx,
imp.options.Logger,
exporter,
func(ctx context.Context, objects <-chan nix.Importable) <-chan error {
return imp.options.WriteIndex.Import(ctx, objects)
},
)
}
|