blob: ac40eaddf100f38dcc4e74e2f21dd2b191201246 (
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
40
|
package fetcher
import (
"context"
"io"
"go.alanpearce.eu/searchix/internal/config"
"go.alanpearce.eu/searchix/internal/index"
"go.alanpearce.eu/x/log"
"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 *log.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
}
|