blob: 7ea0b03d20a60711f49965d5a5e14507d2587cbd (
plain)
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
|
package fetcher
import (
"context"
"io"
"log/slog"
"searchix/internal/config"
"searchix/internal/index"
"github.com/pkg/errors"
)
type FetchedFiles struct {
Revision io.ReadCloser
Options io.ReadCloser
Packages io.ReadCloser
}
type Fetcher interface {
FetchIfNeeded(context.Context, *index.SourceMeta) (FetchedFiles, error)
}
func New(
source *config.Source,
logger *slog.Logger,
) (fetcher Fetcher, err error) {
switch source.Fetcher {
case config.ChannelNixpkgs:
fetcher, err = NewNixpkgsChannelFetcher(source, logger)
case config.Channel:
fetcher, err = NewChannelFetcher(source, logger)
case config.Download:
fetcher, err = NewDownloadFetcher(source, logger)
default:
err = errors.Errorf("unsupported fetcher type %s", source.Fetcher.String())
}
return
}
|